Skip to content

Instantly share code, notes, and snippets.

@obihann
Created February 19, 2015 18:04
Show Gist options
  • Save obihann/2450dbec02c1519fc1d0 to your computer and use it in GitHub Desktop.
Save obihann/2450dbec02c1519fc1d0 to your computer and use it in GitHub Desktop.
Go Composition
package main
import (
"encoding/json"
"fmt"
"log"
)
type (
AStruct struct {
Name string
}
BStruct struct {
AStruct
Color string
}
)
func (this *AStruct) SetName(name string) {
this.Name = name
}
func (this *AStruct) GetName() string {
return this.Name
}
func main() {
bStruct := BStruct{
AStruct: AStruct{
Name: "Jeff",
},
Color: "Red",
}
jsonBody, err := json.Marshal(bStruct)
if err != nil {
log.Fatal(err)
return
}
fmt.Printf("%s\n", jsonBody)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment