wire.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/jwt"
  11. "github.com/go-nunu/nunu-layout-advanced/pkg/log"
  12. "github.com/go-nunu/nunu-layout-advanced/pkg/server/http"
  13. "github.com/go-nunu/nunu-layout-advanced/pkg/sid"
  14. "github.com/google/wire"
  15. "github.com/spf13/viper"
  16. )
  17. var repositorySet = wire.NewSet(
  18. repository.NewDB,
  19. //repository.NewRedis,
  20. repository.NewRepository,
  21. repository.NewTransaction,
  22. repository.NewUserRepository,
  23. )
  24. var serviceSet = wire.NewSet(
  25. service.NewService,
  26. service.NewUserService,
  27. )
  28. var handlerSet = wire.NewSet(
  29. handler.NewHandler,
  30. handler.NewUserHandler,
  31. )
  32. var serverSet = wire.NewSet(
  33. server.NewHTTPServer,
  34. server.NewJob,
  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. }