首先确保 版本在0.5.0 或之上
go get -u github.com/shenyisyn/goft-gin@v0.5.0
分两步:
第一步,写一个config文件,如

  1. type RouterConfig struct {
  2. Goft *goft.Goft `inject:"-"`
  3. IndexClass *classes.IndexClass `inject:"-"`
  4. }
  5. func NewRouterConfig() *RouterConfig {
  6. return &RouterConfig{}
  7. }
  8. func (this *RouterConfig) IndexRoutes() interface{} {
  9. this.Goft.Handle("GET", "/a", this.IndexClass.TestA)
  10. this.Goft.Handle("GET", "/b", this.IndexClass.TestA)
  11. this.Goft.Handle("GET", "/void", this.IndexClass.IndexVoid)
  12. return goft.Empty
  13. }

你可以把所有控制器都注入在RouterConfig中。然后在 下方的函数中,一次性写完

注册路由

  1. goft.Ignite(cros(), errorFunc()).
  2. Config(Configuration.NewMyConfig()).
  3. Attach(fairing.NewGlobalFairing()).
  4. Mount("", classes.NewIndexClass()).
  5. Config(Configuration.NewRouterConfig()) //这句就是注册路由

强烈注意:注册路由的配置 必须写在控制器(Mount函数)下方