pcgamedb/cmd/server.go

37 lines
747 B
Go
Raw Normal View History

2024-09-24 06:17:11 -04:00
package cmd
import (
"pcgamedb/config"
"pcgamedb/server"
"github.com/spf13/cobra"
)
var serverCmd = &cobra.Command{
Use: "server",
Long: "Start API server",
Short: "Start API server",
Run: ServerRun,
}
type serverCommandConfig struct {
Port string
AutoCrawl bool
}
var serverCmdCfg serverCommandConfig
func init() {
serverCmd.Flags().StringVarP(&serverCmdCfg.Port, "port", "p", "8080", "server port")
serverCmd.Flags().BoolVarP(&serverCmdCfg.AutoCrawl, "auto-crawl", "c", true, "enable auto crawl")
RootCmd.AddCommand(serverCmd)
}
func ServerRun(cmd *cobra.Command, args []string) {
if serverCmdCfg.AutoCrawl {
config.Config.Server.AutoCrawl = true
}
config.Config.Server.Port = serverCmdCfg.Port
server.Run()
}