-
-
Save jameshandsoame/33d08fc1824e79f69110ab832ff6c824 to your computer and use it in GitHub Desktop.
Go: bindata で埋め込んだ JSON ファイルを読み出す
This file contains hidden or 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 "fmt" | |
| import "encoding/json" | |
| type Color struct { | |
| Color string `json:"color"` | |
| Value string `json:"value"` | |
| } | |
| func main() { | |
| data, err := Asset("assets/colors.json") | |
| if err != nil { | |
| panic(err) | |
| } | |
| var colors []Color | |
| if err := json.Unmarshal(data, &colors); err != nil { | |
| panic(err) | |
| } | |
| for _, p := range colors { | |
| fmt.Printf("%s, %s\n", p.Color, p.Value) | |
| } | |
| } |
This file contains hidden or 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
| all: assets-json | |
| assets-json: | |
| go-bindata -o bindata.go assets | |
| go build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment