Created
February 19, 2015 18:04
-
-
Save obihann/2450dbec02c1519fc1d0 to your computer and use it in GitHub Desktop.
Go Composition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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