wire.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/repository"
  7. "github.com/go-nunu/nunu-layout-advanced/internal/server"
  8. "github.com/go-nunu/nunu-layout-advanced/internal/service"
  9. "github.com/go-nunu/nunu-layout-advanced/pkg/app"
  10. "github.com/go-nunu/nunu-layout-advanced/pkg/helper/sid"
  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/google/wire"
  15. "github.com/spf13/viper"
  16. )
  17. var handlerSet = wire.NewSet(
  18. handler.NewHandler,
  19. handler.NewUserHandler,
  20. )
  21. var serviceSet = wire.NewSet(
  22. service.NewService,
  23. service.NewUserService,
  24. )
  25. var repositorySet = wire.NewSet(
  26. repository.NewDB,
  27. repository.NewRedis,
  28. repository.NewRepository,
  29. repository.NewUserRepository,
  30. )
  31. var serverSet = wire.NewSet(
  32. server.NewHTTPServer,
  33. server.NewJob,
  34. server.NewTask,
  35. )
  36. // build App
  37. func newApp(httpServer *http.Server, job *server.Job) *app.App {
  38. return app.NewApp(
  39. app.WithServer(httpServer, job),
  40. app.WithName("demo-server"),
  41. )
  42. }
  43. func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
  44. panic(wire.Build(
  45. repositorySet,
  46. serviceSet,
  47. handlerSet,
  48. serverSet,
  49. sid.NewSid,
  50. jwt.NewJwt,
  51. newApp,
  52. ))
  53. }