Files
scheduler/config/config.go

44 lines
913 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"fmt"
"os"
"github.com/golang-module/carbon/v2"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
func Load() {
parseArgs()
readconfig()
fmt.Println(Default)
carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
Timezone: carbon.PRC,
WeekStartsAt: carbon.Monday,
Locale: "zh-CN", // 取值范围lang 目录下翻译文件名,不包含文件后缀
})
}
func readconfig() {
if err := viper.ReadInConfig(); err != nil {
fmt.Printf("Error reading config file: %v\n", err)
os.Exit(1)
}
if err := viper.Unmarshal(&Default); err != nil {
panic(fmt.Errorf("映射配置到结构体失败: %s", err))
}
}
func parseArgs() {
pflag.String("config", "config.yaml", "the path to config file.")
viper.BindPFlags(pflag.CommandLine)
pflag.Parse()
pathToConfigure = viper.GetString("config")
viper.SetConfigFile(pathToConfigure)
}