26. フィールドの情報を取得する(Type)
● タグを取得する
type Hoge struct {
N int `json:"n"`
}
type StructTag string
func main() {
h := Hoge{10}
t := reflect.TypeOf(h)
n, _ := t.FieldByName("N")
fmt.Println(n.Tag.Get("json"))
}
39. 関数を作る - 合成関数を作る
func main() {
f := func(x int) int {
return x * x
}
var g func(x int) int
// 2つの関数を受け取り、第3引数の変数に入れる
Compose(f, f, &g)
fmt.Println(g(2)) // 16
}