wire.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. repository.NewGameShieldRepository,
  21. )
  22. var taskSet = wire.NewSet(
  23. task.NewTask,
  24. task.NewUserTask,
  25. task.NewGameShieldTask,
  26. )
  27. var serverSet = wire.NewSet(
  28. server.NewTaskServer,
  29. )
  30. // build App
  31. func newApp(
  32. task *server.TaskServer,
  33. ) *app.App {
  34. return app.NewApp(
  35. app.WithServer(task),
  36. app.WithName("demo-task"),
  37. )
  38. }
  39. func NewWire(*viper.Viper, *log.Logger) (*app.App, func(), error) {
  40. panic(wire.Build(
  41. repositorySet,
  42. taskSet,
  43. serverSet,
  44. newApp,
  45. sid.NewSid,
  46. ))
  47. }