Skip to content

Instantly share code, notes, and snippets.

@jameshandsoame
Forked from hikobae/assets-json.go
Created July 20, 2017 01:59
Show Gist options
  • Select an option

  • Save jameshandsoame/33d08fc1824e79f69110ab832ff6c824 to your computer and use it in GitHub Desktop.

Select an option

Save jameshandsoame/33d08fc1824e79f69110ab832ff6c824 to your computer and use it in GitHub Desktop.
Go: bindata で埋め込んだ JSON ファイルを読み出す
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)
}
}
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