🎉 完成基本的演示和样例
This commit is contained in:
16
internal/cmd/client.go
Normal file
16
internal/cmd/client.go
Normal file
@ -0,0 +1,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"uauth/internal/client"
|
||||
)
|
||||
|
||||
func initClient() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "client",
|
||||
Short: "Run the client",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return client.Run(cmd.Context())
|
||||
},
|
||||
}
|
||||
}
|
31
internal/cmd/cmd.go
Normal file
31
internal/cmd/cmd.go
Normal file
@ -0,0 +1,31 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/loveuer/nf/nft/log"
|
||||
"github.com/spf13/cobra"
|
||||
"uauth/internal/opt"
|
||||
)
|
||||
|
||||
var (
|
||||
Command = &cobra.Command{
|
||||
Use: "uauth",
|
||||
Short: "uauth: oauth v2 server",
|
||||
Example: "",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
if opt.Cfg.Debug {
|
||||
log.SetLogLevel(log.LogLevelDebug)
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
Command.PersistentFlags().BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode")
|
||||
|
||||
initServe()
|
||||
|
||||
Command.AddCommand(
|
||||
initServe(),
|
||||
initClient(),
|
||||
)
|
||||
}
|
31
internal/cmd/serve.go
Normal file
31
internal/cmd/serve.go
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user