Files
golang-lab4/cmds/root.go
2025-11-07 05:26:09 +08:00

34 lines
591 B
Go

package cmds
import (
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
)
var RootCmd = &cobra.Command{
Use: "lab4",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.BindPFlags(cmd.PersistentFlags())
viper.BindPFlags(cmd.Flags())
cfg := zap.NewProductionConfig()
logger, err := cfg.Build()
if err != nil {
panic(err)
}
zap.ReplaceGlobals(logger)
},
}
func init() {
cobra.EnableTraverseRunHooks = true
RootCmd.AddCommand(serverCmd)
}