MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / InitEnv

Function InitEnv

common/init.go:28–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28func InitEnv() {
29 flag.Parse()
30
31 if *PrintVersion {
32 fmt.Println(Version)
33 os.Exit(0)
34 }
35
36 if *PrintHelp {
37 printHelp()
38 os.Exit(0)
39 }
40
41 if os.Getenv("SESSION_SECRET") != "" {
42 ss := os.Getenv("SESSION_SECRET")
43 if ss == "random_string" {
44 log.Println("WARNING: SESSION_SECRET is set to the default value 'random_string', please change it to a random string.")
45 log.Println("警告:SESSION_SECRET被设置为默认值'random_string',请修改为随机字符串。")
46 log.Fatal("Please set SESSION_SECRET to a random string.")
47 } else {
48 SessionSecret = ss
49 }
50 }
51 if os.Getenv("CRYPTO_SECRET") != "" {
52 CryptoSecret = os.Getenv("CRYPTO_SECRET")
53 } else {
54 CryptoSecret = SessionSecret
55 }
56 if os.Getenv("SQLITE_PATH") != "" {
57 SQLitePath = os.Getenv("SQLITE_PATH")
58 }
59 if *LogDir != "" {
60 var err error
61 *LogDir, err = filepath.Abs(*LogDir)
62 if err != nil {
63 log.Fatal(err)
64 }
65 if _, err := os.Stat(*LogDir); os.IsNotExist(err) {
66 err = os.Mkdir(*LogDir, 0777)
67 if err != nil {
68 log.Fatal(err)
69 }
70 }
71 }
72
73 // Initialize variables from constants.go that were using environment variables
74 DebugEnabled = os.Getenv("DEBUG") == "true"
75 MemoryCacheEnabled = os.Getenv("MEMORY_CACHE_ENABLED") == "true"
76 IsMasterNode = os.Getenv("NODE_TYPE") != "slave"
77
78 // Parse requestInterval and set RequestInterval
79 requestInterval, _ = strconv.Atoi(os.Getenv("POLLING_INTERVAL"))
80 RequestInterval = time.Duration(requestInterval) * time.Second
81
82 // Initialize variables with GetEnvOrDefault
83 SyncFrequency = GetEnvOrDefault("SYNC_FREQUENCY", 60)
84 BatchUpdateInterval = GetEnvOrDefault("BATCH_UPDATE_INTERVAL", 5)
85 RelayTimeout = GetEnvOrDefault("RELAY_TIMEOUT", 0)

Callers 1

InitResourcesFunction · 0.92

Calls 5

printHelpFunction · 0.85
GetEnvOrDefaultFunction · 0.85
GetEnvOrDefaultStringFunction · 0.85
GetEnvOrDefaultBoolFunction · 0.85
initConstantEnvFunction · 0.85

Tested by

no test coverage detected