wire.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 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. server.NewTask,
  36. )
  37. // build App
  38. func newApp(httpServer *http.Server, job *server.Job) *app.App {
  39. return app.NewApp(
  40. app.WithServer(httpServer, job),
  41. app.WithName("demo-server"),
  42. )
  43. }
  44. func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
  45. panic(wire.Build(
  46. repositorySet,
  47. serviceSet,
  48. handlerSet,
  49. serverSet,
  50. sid.NewSid,
  51. jwt.NewJwt,
  52. newApp,
  53. ))
  54. }