From 0dbd898532b0eba3a31b93fa0eb14098adc1f376 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Wed, 29 Nov 2023 14:40:20 +0800 Subject: [PATCH] update config yaml --- config.sample.yaml | 16 ++++++++++++++++ main.go | 10 +++++----- structure.go | 3 +++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 config.sample.yaml diff --git a/config.sample.yaml b/config.sample.yaml new file mode 100644 index 0000000..4971081 --- /dev/null +++ b/config.sample.yaml @@ -0,0 +1,16 @@ +authorization: woshimima + +# 使用 sqlite 作为数据库储存请求记录 +dbtype: sqlite +dbaddr: ./db.sqlite + +# 使用 postgres 作为数据库储存请求记录 +# dbtype: postgres +# dbaddr: "host=127.0.0.1 port=5432 user=postgres dbname=openai_api_route sslmode=disable password=woshimima" + +upstreams: + - sk: "secret_key_1" + endpoint: "https://api.openai.com/v2" + - sk: "secret_key_2" + endpoint: "https://api.openai.com/v1" + timeout: 30 \ No newline at end of file diff --git a/main.go b/main.go index 725f2d8..36c56b1 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,10 @@ func main() { log.Println("Service starting") + // load all upstreams + config = readConfig(*configFile) + log.Println("Load upstreams number:", len(config.Upstreams)) + // connect to database var db *gorm.DB var err error @@ -40,13 +44,9 @@ func main() { SkipDefaultTransaction: true, }) default: - log.Fatalf("Unsupported database type: %s", config.DBType) + log.Fatalf("Unsupported database type: '%s'", config.DBType) } - // load all upstreams - config = readConfig(*configFile) - log.Println("Load upstreams number:", len(config.Upstreams)) - db.AutoMigrate(&Record{}) log.Println("Auto migrate database done") diff --git a/structure.go b/structure.go index 9b4dbf1..ad8037d 100644 --- a/structure.go +++ b/structure.go @@ -37,12 +37,15 @@ func readConfig(filepath string) Config { // set default value if config.Address == "" { + log.Println("Address not set, use default value: :8888") config.Address = ":8888" } if config.DBType == "" { + log.Println("DBType not set, use default value: sqlite") config.DBType = "sqlite" } if config.DBAddr == "" { + log.Println("DBAddr not set, use default value: ./db.sqlite") config.DBAddr = "./db.sqlite" }