uauth/internal/cmd/serve.go

30 lines
827 B
Go
Raw Normal View History

2024-10-23 17:46:15 +08:00
package cmd
2024-10-23 22:42:13 +08:00
import (
"github.com/spf13/cobra"
2024-10-24 18:01:44 +08:00
"uauth/internal/opt"
2024-10-23 22:42:13 +08:00
"uauth/internal/serve"
2024-10-24 18:01:44 +08:00
"uauth/internal/store/cache"
2024-10-27 21:47:57 +08:00
"uauth/internal/store/db"
2024-10-24 18:01:44 +08:00
"uauth/internal/tool"
2024-10-23 22:42:13 +08:00
)
2024-10-23 17:46:15 +08:00
func initServe() *cobra.Command {
2024-10-23 22:42:13 +08:00
svc := &cobra.Command{
Use: "svc",
RunE: func(cmd *cobra.Command, args []string) error {
2024-10-24 18:01:44 +08:00
tool.TablePrinter(opt.Cfg)
tool.Must(cache.Init(opt.Cfg.Svc.Cache))
2024-10-27 21:47:57 +08:00
tool.Must(db.Init(cmd.Context(), opt.Cfg.Svc.DB))
2024-10-24 18:01:44 +08:00
return serve.Run(cmd.Context())
2024-10-23 22:42:13 +08:00
},
2024-10-23 17:46:15 +08:00
}
2024-10-24 18:01:44 +08:00
svc.Flags().StringVar(&opt.Cfg.Svc.Address, "address", "localhost:8080", "listen address")
svc.Flags().StringVar(&opt.Cfg.Svc.Prefix, "prefix", "/api/oauth/v2", "api prefix")
svc.Flags().StringVar(&opt.Cfg.Svc.Cache, "cache", "lru::", "cache uri")
2024-10-27 21:47:57 +08:00
svc.Flags().StringVar(&opt.Cfg.Svc.DB, "db", "sqlite::data.sqlite", "database uri")
2024-10-23 22:42:13 +08:00
return svc
2024-10-23 17:46:15 +08:00
}