go context 可以保存在struct中吗
可以。在struct中定义一个字段,类型为context.Context,即可保存context。例如:
type MyStruct struct {
Ctx context.Context
}
在使用时,可以将context传递给MyStruct的实例:
ctx := context.Background()
myStruct := MyStruct{Ctx: ctx}
原文地址: https://www.cveoy.top/t/topic/bgmK 著作权归作者所有。请勿转载和采集!