wire.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //go:build wireinject
  2. // +build wireinject
  3. package wire
  4. import (
  5. "github.com/go-nunu/nunu-layout-advanced/internal/handler"
  6. "github.com/go-nunu/nunu-layout-advanced/internal/job"
  7. "github.com/go-nunu/nunu-layout-advanced/internal/repository"
  8. "github.com/go-nunu/nunu-layout-advanced/internal/server"
  9. "github.com/go-nunu/nunu-layout-advanced/internal/service"
  10. "github.com/go-nunu/nunu-layout-advanced/pkg/app"
  11. "github.com/go-nunu/nunu-layout-advanced/pkg/jwt"
  12. "github.com/go-nunu/nunu-layout-advanced/pkg/log"
  13. "github.com/go-nunu/nunu-layout-advanced/pkg/server/http"
  14. "github.com/go-nunu/nunu-layout-advanced/pkg/sid"
  15. "github.com/google/wire"
  16. "github.com/spf13/viper"
  17. )
  18. var repositorySet = wire.NewSet(
  19. repository.NewDB,
  20. //repository.NewRedis,
  21. repository.NewRepository,
  22. repository.NewTransaction,
  23. repository.NewUserRepository,
  24. )
  25. var serviceSet = wire.NewSet(
  26. service.NewService,
  27. service.NewUserService,
  28. )
  29. var handlerSet = wire.NewSet(
  30. handler.NewHandler,
  31. handler.NewUserHandler,
  32. )
  33. var jobSet = wire.NewSet(
  34. job.NewJob,
  35. job.NewUserJob,
  36. )
  37. var serverSet = wire.NewSet(
  38. server.NewHTTPServer,
  39. server.NewJobServer,
  40. )
  41. // build App
  42. func newApp(
  43. httpServer *http.Server,
  44. jobServer *server.JobServer,
  45. // task *server.Task,
  46. ) *app.App {
  47. return app.NewApp(
  48. app.WithServer(httpServer, jobServer),
  49. app.WithName("demo-server"),
  50. )
  51. }
  52. func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
  53. panic(wire.Build(
  54. repositorySet,
  55. serviceSet,
  56. handlerSet,
  57. jobSet,
  58. serverSet,
  59. sid.NewSid,
  60. jwt.NewJwt,
  61. newApp,
  62. ))
  63. }