MCPcopy
hub / github.com/QuantumNous/new-api / InitEnv

Function InitEnv

common/init.go:31–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

InitResourcesFunction · 0.92

Calls 6

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

Tested by

no test coverage detected