我希望能够将函数名称传递给 gin.Engine 路由处理程序。我有以下代码;
// status service
type StatusService struct {
App *gin.Engine
}
func (s *StatusService) Ping(ctx *gin.Context) {
ctx.JSON(200, gin.H{
"message": "pong",
})
}
app := gin.Default()
// define services
statusService := &services.StatusService{
App: app,
}
ss := make(map[string]interface{})
ss["auth"] = statusService
app.GET("/ping", ss["auth"].Ping)
编译器给出以下错误;
./app.go:60: ss["auth"].Ping undefined (type interface {} has no field or method Ping)
关于如何解决这个问题的任何想法?
红糖糍粑
相关分类