handler.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package authorized
  2. import (
  3. "github.com/xinliangnote/go-gin-api/configs"
  4. "github.com/xinliangnote/go-gin-api/internal/pkg/core"
  5. "github.com/xinliangnote/go-gin-api/internal/repository/mysql"
  6. "github.com/xinliangnote/go-gin-api/internal/repository/redis"
  7. "github.com/xinliangnote/go-gin-api/internal/services/authorized"
  8. "github.com/xinliangnote/go-gin-api/pkg/hash"
  9. "go.uber.org/zap"
  10. )
  11. var _ Handler = (*handler)(nil)
  12. type Handler interface {
  13. i()
  14. // Create 新增调用方
  15. // @Tags API.authorized
  16. // @Router /api/authorized [post]
  17. Create() core.HandlerFunc
  18. // CreateAPI 授权调用方接口地址
  19. // @Tags API.authorized
  20. // @Router /api/authorized_api [post]
  21. CreateAPI() core.HandlerFunc
  22. // List 调用方列表
  23. // @Tags API.authorized
  24. // @Router /api/authorized [get]
  25. List() core.HandlerFunc
  26. // ListAPI 调用方接口地址列表
  27. // @Tags API.authorized
  28. // @Router /api/authorized_api [get]
  29. ListAPI() core.HandlerFunc
  30. // Delete 删除调用方
  31. // @Tags API.authorized
  32. // @Router /api/authorized/{id} [delete]
  33. Delete() core.HandlerFunc
  34. // DeleteAPI 删除调用方接口地址
  35. // @Tags API.authorized
  36. // @Router /api/authorized_api/{id} [delete]
  37. DeleteAPI() core.HandlerFunc
  38. // UpdateUsed 更新调用方为启用/禁用
  39. // @Tags API.authorized
  40. // @Router /api/authorized/used [patch]
  41. UpdateUsed() core.HandlerFunc
  42. }
  43. type handler struct {
  44. logger *zap.Logger
  45. cache redis.Repo
  46. authorizedService authorized.Service
  47. hashids hash.Hash
  48. }
  49. func New(logger *zap.Logger, db mysql.Repo, cache redis.Repo) Handler {
  50. return &handler{
  51. logger: logger,
  52. cache: cache,
  53. authorizedService: authorized.New(db, cache),
  54. hashids: hash.New(configs.Get().HashIds.Secret, configs.Get().HashIds.Length),
  55. }
  56. }
  57. func (h *handler) i() {}