Controller定义

  1. type UserController struct {
  2. mvc.ApiController
  3. userAction models.IUserAction
  4. }
  5. func NewUserController(userAction models.IUserAction) *UserController {
  6. return &UserController{userAction: userAction}
  7. }
  8. // GET URL http://localhost:8080/v1
  9. func (controller UserController) GetInfo() mvc.ApiResult {
  10. return controller.OK(controller.userAction.Login("zhang"))
  11. }

Main.go

  1. package main
  2. import (
  3. yoyogo "github.com/yoyofx/yoyogo/web"
  4. ......
  5. )
  6. func main() {
  7. configuration := abstractions.NewConfigurationBuilder().
  8. AddEnvironment().
  9. AddYamlFile("config").Build()
  10. yoyogo.NewWebHostBuilder().
  11. UseConfiguration(configuration).
  12. Configure(func(app *yoyogo.WebApplicationBuilder) {
  13. app.UseMvc(func(builder *mvc.ControllerBuilder) {
  14. builder.AddController(contollers.NewUserController)
  15. })
  16. }).Build().Run()
  17. }