package cmd import ( "encoding/base64" "errors" "fmt" "go-admin/cmd/app" "go-admin/cmd/consumer" "go-admin/cmd/gen" "go-admin/common/global" "go-admin/utils" "os" "time" "github.com/go-admin-team/go-admin-core/sdk/pkg" "github.com/spf13/cobra" "go-admin/cmd/alert" "go-admin/cmd/api" "go-admin/cmd/config" "go-admin/cmd/migrate" "go-admin/cmd/neo" "go-admin/cmd/version" ) var rootCmd = &cobra.Command{ Use: "go-admin", Short: "go-admin", SilenceUsage: true, Long: `go-admin`, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { tip() return errors.New(pkg.Red("requires at least one arg")) } return nil }, PersistentPreRunE: func(*cobra.Command, []string) error { return nil }, Run: func(cmd *cobra.Command, args []string) { tip() }, } func tip() { usageStr := `欢迎使用 ` + pkg.Green(`go-admin `+global.Version) + ` 可以使用 ` + pkg.Red(`-h`) + ` 查看命令` usageStr1 := `也可以参考 https://doc.go-admin.dev/guide/ksks 的相关内容` fmt.Printf("%s\n", usageStr) fmt.Printf("%s\n", usageStr1) } func init() { rootCmd.AddCommand(api.StartCmd) rootCmd.AddCommand(migrate.StartCmd) rootCmd.AddCommand(version.StartCmd) rootCmd.AddCommand(config.StartCmd) rootCmd.AddCommand(app.StartCmd) rootCmd.AddCommand(gen.StartCmd) rootCmd.AddCommand(consumer.StartCmd) rootCmd.AddCommand(alert.StartCmd) rootCmd.AddCommand(neo.StartCmd) } // Execute : apply commands func Execute() { fmt.Println("timenow: ", time.Now()) if !checkTime() { fmt.Printf("Trial expired.") os.Exit(-1) } if err := rootCmd.Execute(); err != nil { os.Exit(-1) } } func checkTime() bool { if utils.GetDefaultEnv("RAIKK", "n") == "y" { // 2023.12.30 +++> 1703904495000 +++> MTcwMzkwNDQ5NTAwMA== fmt.Println("check trial...") timePermission64s, err := base64.StdEncoding.DecodeString(utils.GetDefaultEnv("DRTTY", "MjAyMzEyMzA=")) if err != nil { fmt.Println("endcoding err:", err) return false } timePermission, err := time.Parse("20060102", string(timePermission64s)) if err != nil { fmt.Println("trans:", err) return false } currentTime := time.Now() if currentTime.After(timePermission) { return false } } return true }