UserController.go 723 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package admin
  2. import (
  3. "strings"
  4. "think-go/controllers/services"
  5. )
  6. type UserController struct {
  7. BaseController
  8. }
  9. // @router /user/add [get,post]
  10. func (c *UserController) Add() {
  11. c.Ctx.WriteString("this is add user")
  12. }
  13. // @router /user/:id [get]
  14. func (c *UserController) GetUser() {
  15. mobile := c.Ctx.Input.Param(":id")
  16. password := c.GetString("password")
  17. if strings.TrimSpace(mobile) == "" {
  18. c.Error("mobile is required", 400)
  19. return
  20. }
  21. if strings.TrimSpace(password) == "" {
  22. c.Error("password is required", 400)
  23. return
  24. }
  25. svc := &services.SaasUserService{}
  26. result, err := svc.Login(mobile, password)
  27. if err != nil {
  28. c.Error(err.Error(), 400)
  29. return
  30. }
  31. c.Success(result, "login success")
  32. }