今天要学着做web框架的时候,写自己的contex时引入了context.Context接口,找了半天没找到自动生成Context接口的方法,Goland有没有什么自动生成机制或者插件可以自动生成其他包接口的方法啊
type Context struct {
request *http.Request
response http.ResponseWriter
context.Context
//超时设置
hasTimeOut bool
//写保护
writerMux *sync.RWMutex
}
// #endregion
//只能手动写完
func (ctx *Context) BaseContext() context.Context {
return ctx.request.Context()
}
// #region implement context.Context
func (ctx *Context) Deadline() (deadline time.Time, ok bool) {
return ctx.BaseContext().Deadline()
}
func (ctx *Context) Done() <-chan struct{} {
return ctx.BaseContext().Done()
}
func (ctx *Context) Err() error {
return ctx.BaseContext().Err()
}
func (ctx *Context) Value(key interface{}) interface{} {
return ctx.BaseContext().Value(key)
}
选中struct名称,然后使用快捷键 Ctrl + I on Windows/Linux or ^ + I on macOS
然后会弹出来输入框,你直接输入接口的名称来检索,选中你想要实现的接口,回车就可以啦
可以参考jetbrains的官网说明