wip: 登录和认证

This commit is contained in:
loveuer
2025-07-13 22:57:57 +08:00
parent 48af538f98
commit b48fa05d9f
33 changed files with 1961 additions and 33 deletions

View File

@ -6,9 +6,10 @@ import (
"loveuer/utodo/internal/model"
"loveuer/utodo/internal/opt"
g_api "loveuer/utodo/pkg/api"
"loveuer/utodo/pkg/database/cache"
"loveuer/utodo/pkg/tool"
"gitea.loveuer.com/yizhisec/packages/database/db"
"gitea.loveuer.com/yizhisec/packages/tool"
"github.com/spf13/cobra"
)
@ -21,6 +22,7 @@ func svcCmd() *cobra.Command {
cmd.Flags().StringVar(&opt.Cfg.Svc.Address, "address", ":9119", "address to listen on")
cmd.Flags().StringVar(&opt.Cfg.Svc.DBFile, "db", "/data/data.db", "database file")
cmd.Flags().StringVar(&opt.Cfg.Svc.Cache, "cache", "", "cache uri: empty for memory cache; for redis(rdp://user:password@host:port)")
return cmd
}
@ -31,7 +33,14 @@ func svcRun(cmd *cobra.Command, args []string) error {
stopApi func(context.Context) error
)
if err = db.Init(db.WithSqlite(opt.Cfg.Svc.DBFile)); err != nil {
if err = db.Init(db.WithCtx(cmd.Context()), db.WithSqlite(opt.Cfg.Svc.DBFile)); err != nil {
return err
}
if err = cache.Init(
cache.WithCtx(cmd.Context()),
tool.If(opt.Cfg.Svc.Cache == "", cache.WithMemory(), cache.WithRedisURI(opt.Cfg.Svc.Cache)),
); err != nil {
return err
}