構造体で匿名関数を使用して値を更新することはできますか?文字列に動的なid
値を置きます構造体の匿名関数
inspect = lambda id: '/api/{}/inspect'.format(id)
:Pythonで私は、ラムダで次の操作を行います。 Go
で
は、私は彼のようなものをしようとしています:
type Info struct {
Inspect string
}
func Assign() Info {
i := &Info{}
i.Inspect = return func(id) {return fmt.Sprintf("/api/%s/inspect", id)}
return *i
}
しかし、私はこのような値は更新したい:
temp := Assign()
tempID := temp.Inspect("test")
fmt.Println("/api/test/inspect")
ハ!ちょうど私にそれを打つ。 –