wire.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //go:build wireinject
  2. // +build wireinject
  3. package wire
  4. import (
  5. "github.com/go-nunu/nunu-layout-advanced/internal/repository"
  6. "github.com/go-nunu/nunu-layout-advanced/internal/server"
  7. "github.com/go-nunu/nunu-layout-advanced/internal/task"
  8. "github.com/go-nunu/nunu-layout-advanced/pkg/app"
  9. "github.com/go-nunu/nunu-layout-advanced/pkg/log"
  10. "github.com/go-nunu/nunu-layout-advanced/pkg/sid"
  11. "github.com/google/wire"
  12. "github.com/spf13/viper"
  13. )
  14. var repositorySet = wire.NewSet(
  15. repository.NewDB,
  16. //repository.NewRedis,
  17. repository.NewRepository,
  18. repository.NewTransaction,
  19. repository.NewUserRepository,
  20. )
  21. var taskSet = wire.NewSet(
  22. task.NewTask,
  23. task.NewUserTask,
  24. )
  25. var serverSet = wire.NewSet(
  26. server.NewTaskServer,
  27. )
  28. // build App
  29. func newApp(
  30. task *server.TaskServer,
  31. ) *app.App {
  32. return app.NewApp(
  33. app.WithServer(task),
  34. app.WithName("demo-task"),
  35. )
  36. }
  37. func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
  38. panic(wire.Build(
  39. repositorySet,
  40. taskSet,
  41. serverSet,
  42. newApp,
  43. sid.NewSid,
  44. ))
  45. }