MCPcopy Create free account
hub / github.com/ConnectAI-E/Feishu-OpenAI-Stream-Chatbot / LoadConfig

Function LoadConfig

code/initialization/config.go:65–102  ·  view source on GitHub ↗

* LoadConfig will load config and should only be called once, you should always use GetConfig to get config rather than call this function directly */

(cfg string)

Source from the content-addressed store, hash-verified

63call this function directly
64*/
65func LoadConfig(cfg string) *Config {
66 viper.SetConfigFile(cfg)
67 viper.ReadInConfig()
68 viper.AutomaticEnv()
69 //content, err := ioutil.ReadFile("config.yaml")
70 //if err != nil {
71 // fmt.Println("Error reading file:", err)
72 //}
73 //fmt.Println(string(content))
74
75 config := &Config{
76 EnableLog: getViperBoolValue("ENABLE_LOG", false),
77 FeishuAppId: getViperStringValue("APP_ID", ""),
78 FeishuAppSecret: getViperStringValue("APP_SECRET", ""),
79 FeishuAppEncryptKey: getViperStringValue("APP_ENCRYPT_KEY", ""),
80 FeishuAppVerificationToken: getViperStringValue("APP_VERIFICATION_TOKEN", ""),
81 FeishuBotName: getViperStringValue("BOT_NAME", ""),
82 OpenaiApiKeys: getViperStringArray("OPENAI_KEY", nil),
83 HttpPort: getViperIntValue("HTTP_PORT", 9000),
84 HttpsPort: getViperIntValue("HTTPS_PORT", 9001),
85 UseHttps: getViperBoolValue("USE_HTTPS", false),
86 CertFile: getViperStringValue("CERT_FILE", "cert.pem"),
87 KeyFile: getViperStringValue("KEY_FILE", "key.pem"),
88 OpenaiApiUrl: getViperStringValue("API_URL", "https://api.openai.com"),
89 HttpProxy: getViperStringValue("HTTP_PROXY", ""),
90 AzureOn: getViperBoolValue("AZURE_ON", false),
91 AzureApiVersion: getViperStringValue("AZURE_API_VERSION", "2023-03-15-preview"),
92 AzureDeploymentName: getViperStringValue("AZURE_DEPLOYMENT_NAME", ""),
93 AzureResourceName: getViperStringValue("AZURE_RESOURCE_NAME", ""),
94 AzureOpenaiToken: getViperStringValue("AZURE_OPENAI_TOKEN", ""),
95 AccessControlEnable: getViperBoolValue("ACCESS_CONTROL_ENABLE", false),
96 AccessControlMaxCountPerUserPerDay: getViperIntValue("ACCESS_CONTROL_MAX_COUNT_PER_USER_PER_DAY", 0),
97 OpenAIHttpClientTimeOut: getViperIntValue("OPENAI_HTTP_CLIENT_TIMEOUT", 550),
98 OpenaiModel: getViperStringValue("OPENAI_MODEL", "gpt-3.5-turbo"),
99 }
100
101 return config
102}
103
104func getViperStringValue(key string, defaultValue string) string {
105 value := viper.GetString(key)

Callers 1

GetConfigFunction · 0.85

Calls 4

getViperBoolValueFunction · 0.85
getViperStringValueFunction · 0.85
getViperStringArrayFunction · 0.85
getViperIntValueFunction · 0.85

Tested by

no test coverage detected