Skip to content

Instantly share code, notes, and snippets.

@haryx8
Created December 31, 2016 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haryx8/90f7d931cbd31ba53ab645174a9782e1 to your computer and use it in GitHub Desktop.
Save haryx8/90f7d931cbd31ba53ab645174a9782e1 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"log"
)
type Envelope struct {
Type string
Msg interface{}
}
type Sound struct {
Description string
Authority string
}
type Cowbell struct {
More bool
}
func main() {
s := Envelope{
Type: "sound",
Msg: Sound{
Description: "dynamite",
Authority: "the Bruce Dickinson",
},
}
buf, err := json.Marshal(s)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", buf)
c := Envelope{
Type: "cowbell",
Msg: Cowbell{
More: true,
},
}
buf, err = json.Marshal(c)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment