Skip to content

Instantly share code, notes, and snippets.

@joshrendek
Created December 15, 2015 17:01
Show Gist options
  • Save joshrendek/aa73e544609fdb181721 to your computer and use it in GitHub Desktop.
Save joshrendek/aa73e544609fdb181721 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type ServiceResponse struct {
Foobar string
SomethingElse bool
}
type ApiResponse interface {
Respond() interface{}
}
type ApiV1 struct {
Data ServiceResponse
}
type ApiV2 struct {
Data ServiceResponse
}
type V1Response struct {
Banana string
}
type V2Response struct {
Orange bool
}
func (a ApiV1) Respond() {
fmt.Println("[*] V1 Respond()")
fmt.Printf("\t%+v\n", V1Response{Banana: a.Data.Foobar})
}
func (a ApiV2) Respond() {
fmt.Println("[*] V2 Respond()")
fmt.Printf("\t%+v\n", V2Response{Orange: a.Data.SomethingElse})
}
func main() {
v1 := ApiV1{Data: ServiceResponse{Foobar: "halo", SomethingElse: false}}
v2 := ApiV2{Data: ServiceResponse{Foobar: "counter-strike", SomethingElse: true}}
fmt.Println("API demo...")
fmt.Println("V1: ")
v1.Respond()
fmt.Println("V2: ")
v2.Respond()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment