32 lines
885 B
Go
32 lines
885 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"uauth/internal/opt"
|
|
"uauth/internal/serve"
|
|
"uauth/internal/store/cache"
|
|
"uauth/internal/store/db"
|
|
"uauth/internal/tool"
|
|
"uauth/model"
|
|
)
|
|
|
|
func initServe() *cobra.Command {
|
|
svc := &cobra.Command{
|
|
Use: "svc",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
tool.TablePrinter(opt.Cfg)
|
|
tool.Must(cache.Init(opt.Cfg.Svc.Cache))
|
|
tool.Must(db.Init(cmd.Context(), opt.Cfg.Svc.DB))
|
|
tool.Must(model.Init(db.Default.Session()))
|
|
return serve.Run(cmd.Context())
|
|
},
|
|
}
|
|
|
|
svc.Flags().StringVar(&opt.Cfg.Svc.Address, "address", "localhost:8080", "listen address")
|
|
svc.Flags().StringVar(&opt.Cfg.Svc.Prefix, "prefix", "/oauth/v2", "api prefix")
|
|
svc.Flags().StringVar(&opt.Cfg.Svc.Cache, "cache", "lru::", "cache uri")
|
|
svc.Flags().StringVar(&opt.Cfg.Svc.DB, "db", "sqlite::data.sqlite", "database uri")
|
|
|
|
return svc
|
|
}
|