* 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)
| 63 | call this function directly |
| 64 | */ |
| 65 | func 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 | |
| 104 | func getViperStringValue(key string, defaultValue string) string { |
| 105 | value := viper.GetString(key) |
no test coverage detected