update config yaml
This commit is contained in:
16
config.sample.yaml
Normal file
16
config.sample.yaml
Normal file
@@ -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
|
||||||
10
main.go
10
main.go
@@ -25,6 +25,10 @@ func main() {
|
|||||||
|
|
||||||
log.Println("Service starting")
|
log.Println("Service starting")
|
||||||
|
|
||||||
|
// load all upstreams
|
||||||
|
config = readConfig(*configFile)
|
||||||
|
log.Println("Load upstreams number:", len(config.Upstreams))
|
||||||
|
|
||||||
// connect to database
|
// connect to database
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
var err error
|
var err error
|
||||||
@@ -40,13 +44,9 @@ func main() {
|
|||||||
SkipDefaultTransaction: true,
|
SkipDefaultTransaction: true,
|
||||||
})
|
})
|
||||||
default:
|
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{})
|
db.AutoMigrate(&Record{})
|
||||||
log.Println("Auto migrate database done")
|
log.Println("Auto migrate database done")
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,15 @@ func readConfig(filepath string) Config {
|
|||||||
|
|
||||||
// set default value
|
// set default value
|
||||||
if config.Address == "" {
|
if config.Address == "" {
|
||||||
|
log.Println("Address not set, use default value: :8888")
|
||||||
config.Address = ":8888"
|
config.Address = ":8888"
|
||||||
}
|
}
|
||||||
if config.DBType == "" {
|
if config.DBType == "" {
|
||||||
|
log.Println("DBType not set, use default value: sqlite")
|
||||||
config.DBType = "sqlite"
|
config.DBType = "sqlite"
|
||||||
}
|
}
|
||||||
if config.DBAddr == "" {
|
if config.DBAddr == "" {
|
||||||
|
log.Println("DBAddr not set, use default value: ./db.sqlite")
|
||||||
config.DBAddr = "./db.sqlite"
|
config.DBAddr = "./db.sqlite"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user