Skip to content

Commit 2a005bb

Browse files
authored
Merge branch 'chaitin:main' into develop
2 parents 8b26721 + 230aceb commit 2a005bb

34 files changed

Lines changed: 1443 additions & 215 deletions

backend/cmd/server/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// @version 1.0
2020
// @description MonkeyCode API
2121
func main() {
22-
s, err := newServer("/app/config")
22+
s, err := newServer()
2323
if err != nil {
2424
panic(err)
2525
}
@@ -58,7 +58,7 @@ func (s *Server) Name() string {
5858

5959
// Start implements service.Servicer.
6060
func (s *Server) Start() error {
61-
return s.web.Run(s.config.Server.Http.Host)
61+
return s.web.Run(s.config.Server.Addr)
6262
}
6363

6464
// Stop implements service.Servicer.

backend/cmd/server/wire.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Server struct {
3333
billingV1 *billingv1.BillingHandler
3434
}
3535

36-
func newServer(dir string) (*Server, error) {
36+
func newServer() (*Server, error) {
3737
wire.Build(
3838
wire.Struct(new(Server), "*"),
3939
appSet,

backend/cmd/server/wire_gen.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/config/config.go

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package config
22

33
import (
44
_ "embed"
5+
"strings"
56

67
"github.com/spf13/viper"
78

8-
"github.com/chaitin/MonkeyCode/backend/pkg/cvt"
99
"github.com/chaitin/MonkeyCode/backend/pkg/logger"
1010
)
1111

@@ -20,9 +20,7 @@ type Config struct {
2020
BaseUrl string `mapstructure:"base_url"`
2121

2222
Server struct {
23-
Http struct {
24-
Host string `mapstructure:"host"`
25-
} `mapstructure:"http"`
23+
Addr string `mapstructure:"addr"`
2624
} `mapstructure:"server"`
2725

2826
Admin struct {
@@ -51,52 +49,61 @@ type Config struct {
5149
} `mapstructure:"redis"`
5250

5351
LLMProxy struct {
54-
Timeout string `mapstructure:"timeout"`
55-
KeepAlive string `mapstructure:"keep_alive"`
56-
ClientPoolSize int `mapstructure:"client_pool_size"`
57-
RequestLogPath string `mapstructure:"request_log_path"`
52+
Timeout string `mapstructure:"timeout"`
53+
KeepAlive string `mapstructure:"keep_alive"`
54+
ClientPoolSize int `mapstructure:"client_pool_size"`
55+
StreamClientPoolSize int `mapstructure:"stream_client_pool_size"`
56+
RequestLogPath string `mapstructure:"request_log_path"`
5857
} `mapstructure:"llm_proxy"`
5958

6059
InitModel struct {
61-
ModelName string `mapstructure:"model_name"`
62-
ModelKey string `mapstructure:"model_key"`
63-
ModelURL string `mapstructure:"model_url"`
60+
Name string `mapstructure:"name"`
61+
Key string `mapstructure:"key"`
62+
URL string `mapstructure:"url"`
6463
} `mapstructure:"init_model"`
6564

6665
Extension struct {
6766
Baseurl string `mapstructure:"baseurl"`
6867
} `mapstructure:"extension"`
6968
}
7069

71-
func Init(dir string) (*Config, error) {
72-
viper.SetConfigName("config")
73-
viper.SetConfigType("yaml")
74-
viper.AddConfigPath(dir)
75-
if err := viper.ReadInConfig(); err != nil {
76-
return nil, err
77-
}
70+
func Init() (*Config, error) {
71+
v := viper.New()
72+
v.AutomaticEnv()
73+
v.SetEnvPrefix("MONKEYCODE")
74+
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
75+
76+
v.SetDefault("debug", false)
77+
v.SetDefault("logger.level", "info")
78+
v.SetDefault("base_url", "")
79+
v.SetDefault("server.addr", ":8888")
80+
v.SetDefault("admin.user", "admin")
81+
v.SetDefault("admin.password", "")
82+
v.SetDefault("session.expire_day", 30)
83+
v.SetDefault("database.master", "")
84+
v.SetDefault("database.slave", "")
85+
v.SetDefault("database.max_open_conns", 50)
86+
v.SetDefault("database.max_idle_conns", 10)
87+
v.SetDefault("database.conn_max_lifetime", 30)
88+
v.SetDefault("redis.host", "monkeycode-redis")
89+
v.SetDefault("redis.port", "6379")
90+
v.SetDefault("redis.pass", "")
91+
v.SetDefault("redis.db", 0)
92+
v.SetDefault("redis.idle_conn", 20)
93+
v.SetDefault("llm_proxy.timeout", "30s")
94+
v.SetDefault("llm_proxy.keep_alive", "60s")
95+
v.SetDefault("llm_proxy.client_pool_size", 100)
96+
v.SetDefault("llm_proxy.stream_client_pool_size", 5000)
97+
v.SetDefault("llm_proxy.request_log_path", "/app/request/logs")
98+
v.SetDefault("init_model.name", "qwen2.5-coder-3b-instruct")
99+
v.SetDefault("init_model.key", "")
100+
v.SetDefault("init_model.url", "https://model-square.app.baizhi.cloud/v1")
101+
v.SetDefault("extension.baseurl", "https://release.baizhi.cloud")
78102

79103
c := Config{}
80-
if err := viper.Unmarshal(&c); err != nil {
104+
if err := v.Unmarshal(&c); err != nil {
81105
return nil, err
82106
}
83107

84-
c = defaultValue(c)
85108
return &c, nil
86109
}
87-
88-
func defaultValue(c Config) Config {
89-
c.Server.Http.Host = cvt.ZeroWithDefault(c.Server.Http.Host, ":8888")
90-
c.Redis.IdleConn = cvt.ZeroWithDefault(c.Redis.IdleConn, 20)
91-
c.Database.MaxOpenConns = cvt.ZeroWithDefault(c.Database.MaxOpenConns, 50)
92-
c.Database.MaxIdleConns = cvt.ZeroWithDefault(c.Database.MaxIdleConns, 10)
93-
c.Database.ConnMaxLifetime = cvt.ZeroWithDefault(c.Database.ConnMaxLifetime, 30)
94-
c.Session.ExpireDay = cvt.ZeroWithDefault(c.Session.ExpireDay, 15)
95-
96-
c.LLMProxy.Timeout = cvt.ZeroWithDefault(c.LLMProxy.Timeout, "30s")
97-
c.LLMProxy.KeepAlive = cvt.ZeroWithDefault(c.LLMProxy.KeepAlive, "60s")
98-
c.LLMProxy.ClientPoolSize = cvt.ZeroWithDefault(c.LLMProxy.ClientPoolSize, 100)
99-
c.LLMProxy.RequestLogPath = cvt.ZeroWithDefault(c.LLMProxy.RequestLogPath, "/app/request/logs")
100-
101-
return c
102-
}

backend/consts/user.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ type OAuthKind string
2828
const (
2929
OAuthKindSignUpOrIn OAuthKind = "signup_or_in"
3030
)
31+
32+
type InviteCodeStatus string
33+
34+
const (
35+
InviteCodeStatusPending InviteCodeStatus = "pending"
36+
InviteCodeStatusUsed InviteCodeStatus = "used"
37+
)

backend/db/invitecode.go

Lines changed: 26 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/db/invitecode/invitecode.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)