34 lines
969 B
Go
34 lines
969 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
"uauth/internal/opt"
|
|
"uauth/internal/serve"
|
|
"uauth/model"
|
|
"uauth/pkg/cache"
|
|
"uauth/pkg/rbac"
|
|
"uauth/pkg/store"
|
|
"uauth/tool"
|
|
)
|
|
|
|
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(store.Init(opt.Cfg.Svc.DB, store.Config{Debug: opt.Cfg.Debug}))
|
|
tool.Must(model.Init(store.Default.Session(tool.Timeout())))
|
|
tool.Must(rbac.Init(store.Default, cache.Client))
|
|
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
|
|
}
|