mir: fixed http service initial error by wrong ReadTimeout/WriteTimeout setting

pull/196/head
Michael Li 2 years ago
parent 10e5bc470a
commit 275e132927
No known key found for this signature in database

@ -316,13 +316,12 @@ release/paopao-ce --no-default-features --features sqlite3,localoss,loggerfile,r
目前支持的功能集合:
| 功能项 | 类别 | 状态 | 备注 |
| ----- | ----- | ----- | ----- |
|`OldWeb` | 子服务 | 稳定(默认) | 开启旧的Web服务 |
|`Web` | 子服务 | WIP | 开启Web服务|
|`Admin` | 子服务 | WIP | 开启Admin后台运维服务|
|`SpaceX` | 子服务 | WIP | 开启SpaceX服务|
|`Bot` | 子服务 | WIP | 开启Bot服务|
|`NativeOBS` | 子服务 | WIP | 开启NativeOBS服务|
|`Deprecated:Web` | 子服务 | 稳定 | Deprecated(关闭) OldWeb服务|
|`Deprecated:Web` | 子服务 | 稳定 | 开启旧的Web服务|
|`Gorm` | 数据库 | 稳定(默认) | 使用[gorm](https://github.com/go-gorm/gorm)作为数据库的ORM默认使用 `Gorm` + `MySQL`组合|
|`Sqlx`| 数据库 | WIP | 使用[sqlx](https://github.com/jmoiron/sqlx)作为数据库的ORM|
|`MySQL`| 数据库 | 稳定(默认) | 使用MySQL作为数据库|

@ -12,14 +12,14 @@ Server: # 服务设置
ReadTimeout: 60
WriteTimeout: 60
Features:
Default: ["Base", "MySQL", "Option", "Zinc", "LocalOSS", "LoggerFile", "Friendship"]
Default: ["Base", "MySQL", "Option", "Zinc", "LocalOSS", "LoggerFile", "Friendship", "Deprecated"]
Develop: ["Base", "MySQL", "BigCacheIndex", "Meili", "Sms", "AliOSS", "LoggerMeili", "OSS:Retention"]
Demo: ["Base", "MySQL", "Option", "Zinc", "Sms", "MinIO", "LoggerZinc", "Migration"]
Slim: ["Base", "Sqlite3", "LocalOSS", "LoggerFile", "OSS:TempDir"]
Base: ["Redis", "PhoneBind"]
Docs: ["Docs:OpenAPI"]
Deprecated: ["Deprecated:OldWeb"]
Service: ["Admin", "SpaceX", "Bot", "LocalOSS", "Mobile"]
Service: ["Web", "Admin", "SpaceX", "Bot", "LocalOSS", "Mobile"]
Option: ["SimpleCacheIndex"]
Sms: "SmsJuhe"
WebServer: # Web服务

@ -105,8 +105,6 @@ func setupSetting(suite []string, noDefault bool) error {
}
JWTSetting.Expire *= time.Second
ServerSetting.ReadTimeout *= time.Second
ServerSetting.WriteTimeout *= time.Second
SimpleCacheIndexSetting.CheckTickDuration *= time.Second
SimpleCacheIndexSetting.ExpireTickDuration *= time.Second
BigCacheIndexSetting.ExpireInSecond *= time.Second

@ -270,6 +270,14 @@ func (s *Setting) featuresInfoFrom(k string) (map[string][]string, map[string]st
return suites, kv
}
func (s *HttpServerSettingS) GetReadTimeout() time.Duration {
return s.ReadTimeout * time.Second
}
func (s *HttpServerSettingS) GetWriteTimeout() time.Duration {
return s.WriteTimeout * time.Second
}
func (s *MySQLSettingS) Dsn() string {
return fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=%s&parseTime=%t&loc=Local",
s.UserName,

@ -37,7 +37,7 @@ type BaseRender types.Empty
type JsonResp struct {
Code int `json:"code"`
Msg string `json:"msg,omitempty"`
Data any `json:",omitempty"`
Data any `json:"data,omitempty"`
}
type UserSetter interface {

@ -35,7 +35,7 @@ type looseRender struct {
*api.UnimplementedLooseRender
}
func (s *looseSrv) BindTimeline(c *gin.Context) (*web.TimelineReq, mir.Error) {
func (s *looseBinding) BindTimeline(c *gin.Context) (*web.TimelineReq, mir.Error) {
user, _ := base.UserFrom(c)
page, pageSize := app.GetPageInfo(c)
v := &web.TimelineReq{

@ -82,8 +82,8 @@ func newAdminService() Service {
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.AdminServerSetting.ReadTimeout,
WriteTimeout: conf.AdminServerSetting.WriteTimeout,
ReadTimeout: conf.AdminServerSetting.GetReadTimeout(),
WriteTimeout: conf.AdminServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}

@ -82,8 +82,8 @@ func newBotService() Service {
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.BotServerSetting.ReadTimeout,
WriteTimeout: conf.BotServerSetting.WriteTimeout,
ReadTimeout: conf.BotServerSetting.GetReadTimeout(),
WriteTimeout: conf.BotServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}

@ -57,8 +57,8 @@ func newLocalossService() Service {
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.LocalossServerSetting.ReadTimeout,
WriteTimeout: conf.LocalossServerSetting.WriteTimeout,
ReadTimeout: conf.LocalossServerSetting.GetReadTimeout(),
WriteTimeout: conf.LocalossServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}

@ -58,12 +58,11 @@ func MaxSidSize(ss []Service) int {
}
func newService() (ss []Service) {
// add oldWebService if not depredcated OldWebService
cfg.Not("Deprecated:OldWeb", func() {
ss = append(ss, newOldWebService())
})
// add all service if declared in features on config.yaml
cfg.In(cfg.Actions{
"Deprecated:OldWeb": func() {
ss = append(ss, newOldWebService())
},
"Web": func() {
ss = append(ss, newWebService())
},

@ -82,8 +82,8 @@ func newSpaceXService() Service {
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.SpaceXServerSetting.ReadTimeout,
WriteTimeout: conf.SpaceXServerSetting.WriteTimeout,
ReadTimeout: conf.SpaceXServerSetting.GetReadTimeout(),
WriteTimeout: conf.SpaceXServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}

@ -82,12 +82,13 @@ func newWebService() Service {
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.WebServerSetting.ReadTimeout,
WriteTimeout: conf.WebServerSetting.WriteTimeout,
ReadTimeout: conf.WebServerSetting.GetReadTimeout(),
WriteTimeout: conf.WebServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}
})
return &webService{
baseHttpService: &baseHttpService{
server: server,

@ -49,8 +49,8 @@ func newOldWebService() Service {
server: &http.Server{
Addr: addr,
Handler: engine,
ReadTimeout: conf.ServerSetting.ReadTimeout,
WriteTimeout: conf.ServerSetting.WriteTimeout,
ReadTimeout: conf.ServerSetting.GetReadTimeout(),
WriteTimeout: conf.ServerSetting.GetWriteTimeout(),
MaxHeaderBytes: 1 << 20,
},
}

@ -99,6 +99,6 @@ func main() {
wg.Wait()
} else {
fmt.Fprintf(color.Output, "no service need start so just exit")
fmt.Fprintln(color.Output, "no service need start so just exit")
}
}

Loading…
Cancel
Save