go-zero/rest/config.go

64 lines
1.8 KiB
Go
Raw Normal View History

2020-07-31 11:14:48 +08:00
package rest
2020-07-26 17:09:05 +08:00
import (
"time"
"github.com/zeromicro/go-zero/core/service"
2020-07-26 17:09:05 +08:00
)
type (
// MiddlewaresConf is the config of middlewares.
MiddlewaresConf struct {
Trace bool `json:",default=true"`
Log bool `json:",default=true"`
Prometheus bool `json:",default=true"`
MaxConns bool `json:",default=true"`
Breaker bool `json:",default=true"`
Shedding bool `json:",default=true"`
Timeout bool `json:",default=true"`
Recover bool `json:",default=true"`
Metrics bool `json:",default=true"`
MaxBytes bool `json:",default=true"`
Gunzip bool `json:",default=true"`
}
2021-03-01 19:15:35 +08:00
// A PrivateKeyConf is a private key config.
2020-07-26 17:09:05 +08:00
PrivateKeyConf struct {
Fingerprint string
KeyFile string
}
2021-03-01 19:15:35 +08:00
// A SignatureConf is a signature config.
2020-07-26 17:09:05 +08:00
SignatureConf struct {
Strict bool `json:",default=false"`
Expiry time.Duration `json:",default=1h"`
PrivateKeys []PrivateKeyConf
}
2021-03-01 19:15:35 +08:00
// A RestConf is a http service config.
2020-10-29 17:44:51 +08:00
// Why not name it as Conf, because we need to consider usage like:
2021-03-01 19:15:35 +08:00
// type Config struct {
2020-09-18 11:41:52 +08:00
// zrpc.RpcConf
2020-07-31 11:45:16 +08:00
// rest.RestConf
2021-03-01 19:15:35 +08:00
// }
2020-07-31 11:14:48 +08:00
// if with the name Conf, there will be two Conf inside Config.
2020-07-31 11:45:16 +08:00
RestConf struct {
2020-07-26 17:09:05 +08:00
service.ServiceConf
Host string `json:",default=0.0.0.0"`
Port int
2020-10-29 17:44:51 +08:00
CertFile string `json:",optional"`
KeyFile string `json:",optional"`
Verbose bool `json:",optional"`
MaxConns int `json:",default=10000"`
MaxBytes int64 `json:",default=1048576"`
2020-07-26 17:09:05 +08:00
// milliseconds
Timeout int64 `json:",default=3000"`
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
Signature SignatureConf `json:",optional"`
// There are default values for all the items in Middlewares.
Middlewares MiddlewaresConf
// TraceIgnorePaths is paths blacklist for trace middleware.
TraceIgnorePaths []string `json:",optional"`
2020-07-26 17:09:05 +08:00
}
)