package bootstrap import ( "allapp-go/internal/bootstrap/boots" "allapp-go/internal/config" "allapp-go/pkg/db" "allapp-go/pkg/logger" "allapp-go/pkg/s3store" "allapp-go/pkg/wechat" "github.com/jackc/pgx/v5/pgxpool" ) type App struct { Config *config.Config PgSql *pgxpool.Pool } // ====================== // 初始化 // ====================== func NewApp() (*App, error) { cfg, err := config.Load() if err != nil { return nil, err } // 日志 boots.InitLogger(cfg) // S3 s3store.NewS3Client(cfg) // 数据库 pgsql, err := boots.InitPgsql(cfg) if err != nil { return nil, err } db.Init(pgsql) // 其他组件 boots.InitUniqueId(cfg) boots.InitJwt(cfg) wechat.Init(cfg.Wechat.AppId, cfg.Wechat.AppSecret) return &App{ Config: cfg, PgSql: pgsql, }, nil } // ====================== // 释放资源 // ====================== func (a *App) Close() { if a.PgSql != nil { a.PgSql.Close() } logger.Sync() }