mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-02-03 23:33:37 +08:00
114 lines
3.3 KiB
Go
114 lines
3.3 KiB
Go
package config
|
|
|
|
import (
|
|
_ "embed"
|
|
"strings"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/chaitin/MonkeyCode/backend/pkg/logger"
|
|
)
|
|
|
|
//go:embed config.json.tmpl
|
|
var ConfigTmpl []byte
|
|
|
|
type Config struct {
|
|
Debug bool `mapstructure:"debug"`
|
|
|
|
Logger *logger.Config `mapstructure:"logger"`
|
|
|
|
BaseUrl string `mapstructure:"base_url"`
|
|
|
|
Server struct {
|
|
Addr string `mapstructure:"addr"`
|
|
} `mapstructure:"server"`
|
|
|
|
Admin struct {
|
|
User string `mapstructure:"user"`
|
|
Password string `mapstructure:"password"`
|
|
} `mapstructure:"admin"`
|
|
|
|
Session struct {
|
|
ExpireDay int `mapstructure:"expire_day"`
|
|
} `mapstructure:"session"`
|
|
|
|
Database struct {
|
|
Master string `mapstructure:"master"`
|
|
Slave string `mapstructure:"slave"`
|
|
MaxOpenConns int `mapstructure:"max_open_conns"`
|
|
MaxIdleConns int `mapstructure:"max_idle_conns"`
|
|
ConnMaxLifetime int `mapstructure:"conn_max_lifetime"`
|
|
} `mapstructure:"database"`
|
|
|
|
Redis struct {
|
|
Host string `mapstructure:"host"`
|
|
Port string `mapstructure:"port"`
|
|
Pass string `mapstructure:"pass"`
|
|
DB int `mapstructure:"db"`
|
|
IdleConn int `mapstructure:"idle_conn"`
|
|
} `mapstructure:"redis"`
|
|
|
|
LLMProxy struct {
|
|
Timeout string `mapstructure:"timeout"`
|
|
KeepAlive string `mapstructure:"keep_alive"`
|
|
ClientPoolSize int `mapstructure:"client_pool_size"`
|
|
StreamClientPoolSize int `mapstructure:"stream_client_pool_size"`
|
|
RequestLogPath string `mapstructure:"request_log_path"`
|
|
} `mapstructure:"llm_proxy"`
|
|
|
|
InitModel struct {
|
|
Name string `mapstructure:"name"`
|
|
Key string `mapstructure:"key"`
|
|
URL string `mapstructure:"url"`
|
|
} `mapstructure:"init_model"`
|
|
|
|
Extension struct {
|
|
Baseurl string `mapstructure:"baseurl"`
|
|
LimitSecond int `mapstructure:"limit_second"`
|
|
Limit int `mapstructure:"limit"`
|
|
} `mapstructure:"extension"`
|
|
}
|
|
|
|
func Init() (*Config, error) {
|
|
v := viper.New()
|
|
v.AutomaticEnv()
|
|
v.SetEnvPrefix("MONKEYCODE")
|
|
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
|
|
v.SetDefault("debug", false)
|
|
v.SetDefault("logger.level", "info")
|
|
v.SetDefault("base_url", "")
|
|
v.SetDefault("server.addr", ":8888")
|
|
v.SetDefault("admin.user", "admin")
|
|
v.SetDefault("admin.password", "")
|
|
v.SetDefault("session.expire_day", 30)
|
|
v.SetDefault("database.master", "")
|
|
v.SetDefault("database.slave", "")
|
|
v.SetDefault("database.max_open_conns", 50)
|
|
v.SetDefault("database.max_idle_conns", 10)
|
|
v.SetDefault("database.conn_max_lifetime", 30)
|
|
v.SetDefault("redis.host", "monkeycode-redis")
|
|
v.SetDefault("redis.port", "6379")
|
|
v.SetDefault("redis.pass", "")
|
|
v.SetDefault("redis.db", 0)
|
|
v.SetDefault("redis.idle_conn", 20)
|
|
v.SetDefault("llm_proxy.timeout", "30s")
|
|
v.SetDefault("llm_proxy.keep_alive", "60s")
|
|
v.SetDefault("llm_proxy.client_pool_size", 100)
|
|
v.SetDefault("llm_proxy.stream_client_pool_size", 5000)
|
|
v.SetDefault("llm_proxy.request_log_path", "/app/request/logs")
|
|
v.SetDefault("init_model.name", "qwen2.5-coder-3b-instruct")
|
|
v.SetDefault("init_model.key", "")
|
|
v.SetDefault("init_model.url", "https://model-square.app.baizhi.cloud/v1")
|
|
v.SetDefault("extension.baseurl", "https://release.baizhi.cloud")
|
|
v.SetDefault("extension.limit", 1)
|
|
v.SetDefault("extension.limit_second", 10)
|
|
|
|
c := Config{}
|
|
if err := v.Unmarshal(&c); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &c, nil
|
|
}
|