Skip to content

Mvc Controller

YoyoFx edited this page Jul 23, 2020 · 3 revisions

Controller定义

type UserController struct {
	Mvc.ApiController
	userAction models.IUserAction
}

func NewUserController(userAction models.IUserAction) *UserController {
	return &UserController{userAction: userAction}
}

func (controller UserController) GetInfo() Mvc.ApiResult {
	return controller.OK(controller.userAction.Login("zhang"))
}

Main.go

package main
import ...

func main() {
    YoyoGo.NewWebHostBuilder().
           SetEnvironment(Context.Prod).
           UseFastHttp().
           Configure(func(app *YoyoGo.WebApplicationBuilder) {
               app.UseMvc(func(builder *Mvc.ControllerBuilder) {
                   builder.AddController(contollers.NewUserController)
               })
          }).Build().Run()
}