pcgamedb/cmd/server.go
nite07 304517e241
Some checks failed
release / goreleaser (push) Failing after 2m23s
docker / prepare-and-build (push) Failing after 2m55s
trans to private
2024-11-20 19:09:04 +08:00

37 lines
747 B
Go

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()
}