Skip to content

Commit

Permalink
自定义env位置
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkirk-sudo committed Dec 18, 2023
1 parent 02d7870 commit d30ec1e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func main() {
Env: &env.Env,
Auth: funcaptcha.GetOpenAIArkoseToken,
}
var plugins []plugins.Plugin
plugins = append(
plugins,
var plugin_list []plugins.Plugin
plugin_list = append(
plugin_list,
&arkosetoken.ArkoseTokenInstance,
&session.SessionTokenInstance,
&backendapi.BackendProcessInstance,
Expand All @@ -71,7 +71,7 @@ func main() {
&rapi.ApiProcessInstance,
&proxypool.ProxyPoolInstance,
)
for _, plugin := range plugins {
for _, plugin := range plugin_list {
plugin.Run(component)
}
router.Any("/*path", func(context *gin.Context) {
Expand Down
67 changes: 33 additions & 34 deletions pkg/env/env.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
package env

import (
"flag"
"github.com/joho/godotenv"
"os"
"strconv"
)

type ENV struct {
Proxy string
Port int
Host string
Verify bool
AuthKey string
ArkoseMust bool
OpenaiHost string
OpenaiApiHost string
ProxyPoolUrl string
UserAgent string
LogLevel string
RedisAddress string
RedisPasswd string
RedisDB int
Proxy string
Port int
Host string
Verify bool
AuthKey string
ArkoseMust bool
OpenaiHost string
ProxyPoolUrl string
UserAgent string
LogLevel string
RedisAddress string
RedisPasswd string
RedisDB int
PostgreSQLDBURI string
}

var Env ENV
var EnvFile string

func init() {
err := godotenv.Load()
flag.StringVar(&EnvFile, "e", ".env", "The env file path")
flag.Parse()
err := godotenv.Load(EnvFile)
if err != nil {
return
}
Expand All @@ -46,10 +50,6 @@ func init() {
if OpenaiHost == "" {
OpenaiHost = "chat.openai.com"
}
openaiApiHost := os.Getenv("openai_api_host")
if openaiApiHost == "" {
openaiApiHost = "api.openai.com"
}
loglevel := os.Getenv("log_level")
if loglevel == "" {
loglevel = "info"
Expand All @@ -59,25 +59,24 @@ func init() {
if proxyPoolUrl != "" && redisAddress == "" {
panic("配置proxyPoolUrl后未配置redis_address")
}
redisPasswd := os.Getenv("redis_passwd")
redisDb, err := strconv.Atoi(os.Getenv("redis_db"))
if err != nil && proxyPoolUrl != "" {
panic("DB填写出现问题")
}
Env = ENV{
Proxy: os.Getenv("proxy"),
Port: port,
Host: os.Getenv("host"),
Verify: verify,
AuthKey: os.Getenv("auth_key"),
ArkoseMust: arkoseMust,
OpenaiHost: OpenaiHost,
OpenaiApiHost: openaiApiHost,
ProxyPoolUrl: proxyPoolUrl,
UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15",
LogLevel: loglevel,
RedisAddress: redisAddress,
RedisPasswd: redisPasswd,
RedisDB: redisDb,
Proxy: os.Getenv("proxy"),
Port: port,
Host: os.Getenv("host"),
Verify: verify,
AuthKey: os.Getenv("auth_key"),
ArkoseMust: arkoseMust,
OpenaiHost: OpenaiHost,
ProxyPoolUrl: proxyPoolUrl,
UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15",
LogLevel: loglevel,
RedisAddress: redisAddress,
RedisPasswd: os.Getenv("redis_passwd"),
RedisDB: redisDb,
PostgreSQLDBURI: os.Getenv("postgreSQL_db_URI"),
}
}

0 comments on commit d30ec1e

Please sign in to comment.