100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
// Code generated by Wire. DO NOT EDIT.
|
|
|
|
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
|
|
//go:build !wireinject
|
|
// +build !wireinject
|
|
|
|
package main
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/redis/go-redis/v9"
|
|
"gorm.io/gorm"
|
|
"net/http"
|
|
"sub2api/internal/config"
|
|
"sub2api/internal/handler"
|
|
"sub2api/internal/repository"
|
|
"sub2api/internal/service"
|
|
)
|
|
|
|
import (
|
|
_ "embed"
|
|
)
|
|
|
|
// Injectors from wire.go:
|
|
|
|
func initializeApplication(buildInfo handler.BuildInfo) (*Application, error) {
|
|
config, err := provideConfig()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
db, err := provideDB(config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
repositories := provideRepositories(db)
|
|
client := provideRedis(config)
|
|
services := provideServices(repositories, client, config)
|
|
handlers := provideHandlers(services, repositories, client, buildInfo)
|
|
engine := provideRouter(config, handlers, services, repositories)
|
|
server := provideHTTPServer(config, engine)
|
|
v := provideCleanup()
|
|
application := &Application{
|
|
Server: server,
|
|
Cleanup: v,
|
|
}
|
|
return application, nil
|
|
}
|
|
|
|
// wire.go:
|
|
|
|
type Application struct {
|
|
Server *http.Server
|
|
Cleanup func()
|
|
}
|
|
|
|
func provideConfig() (*config.Config, error) {
|
|
return config.Load()
|
|
}
|
|
|
|
func provideDB(cfg *config.Config) (*gorm.DB, error) {
|
|
return initDB(cfg)
|
|
}
|
|
|
|
func provideRedis(cfg *config.Config) *redis.Client {
|
|
return initRedis(cfg)
|
|
}
|
|
|
|
func provideRepositories(db *gorm.DB) *repository.Repositories {
|
|
return repository.NewRepositories(db)
|
|
}
|
|
|
|
func provideServices(repos *repository.Repositories, rdb *redis.Client, cfg *config.Config) *service.Services {
|
|
return service.NewServices(repos, rdb, cfg)
|
|
}
|
|
|
|
func provideHandlers(services *service.Services, repos *repository.Repositories, rdb *redis.Client, buildInfo handler.BuildInfo) *handler.Handlers {
|
|
return handler.NewHandlers(services, repos, rdb, buildInfo)
|
|
}
|
|
|
|
func provideRouter(cfg *config.Config, handlers *handler.Handlers, services *service.Services, repos *repository.Repositories) *gin.Engine {
|
|
if cfg.Server.Mode == "release" {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
}
|
|
|
|
r := gin.New()
|
|
r.Use(gin.Recovery())
|
|
|
|
return setupRouter(r, cfg, handlers, services, repos)
|
|
}
|
|
|
|
func provideHTTPServer(cfg *config.Config, router *gin.Engine) *http.Server {
|
|
return createHTTPServer(cfg, router)
|
|
}
|
|
|
|
func provideCleanup() func() {
|
|
return func() {
|
|
|
|
}
|
|
}
|