linzhengen / tech-notes

My tech notes write in github issues🧲
1 stars 0 forks source link

[20210909] go1.16の `go:embed` 知らなかったよ #141

Open linzhengen opened 3 years ago

linzhengen commented 3 years ago

使い方

import ( _ "embed" "encoding/json" "fmt" )

//go:embed sample.json var sampleBytes []byte

type sample struct { Key1 string json:"key1" Key2 string json:"key2" }

func main() { var s sample if err := json.Unmarshal(sampleBytes, &s); err != nil { panic(err) } fmt.Printf("%+v\n", s) }