Подготовить HY2XS к production-сборке
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"hy2xs-admin/model/constant"
|
||||
"hy2xs-admin/util"
|
||||
"os"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "hy2xs-admin",
|
||||
Short: "HY2XS admin panel for Hysteria2",
|
||||
Long: "HY2XS admin panel for Hysteria2.",
|
||||
Run: run,
|
||||
}
|
||||
|
||||
var (
|
||||
version bool
|
||||
port string
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().BoolVarP(&version, "version", "v", false, "Show version")
|
||||
rootCmd.Flags().StringVarP(&port, "port", "p", "", "The port of the web server")
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) {
|
||||
if version {
|
||||
fmt.Println("HY2XS admin version", constant.Version)
|
||||
return
|
||||
}
|
||||
|
||||
if err := util.VerifyPort(port); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
for {
|
||||
if err := runServer(port); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user