support https in rest

master
kevin 4 years ago
parent 9b7cc43dcb
commit 5e87b33b23

@ -18,7 +18,7 @@ type (
PrivateKeys []PrivateKeyConf PrivateKeys []PrivateKeyConf
} }
// why not name it as Conf, because we need to consider usage like: // Why not name it as Conf, because we need to consider usage like:
// type Config struct { // type Config struct {
// zrpc.RpcConf // zrpc.RpcConf
// rest.RestConf // rest.RestConf
@ -28,6 +28,8 @@ type (
service.ServiceConf service.ServiceConf
Host string `json:",default=0.0.0.0"` Host string `json:",default=0.0.0.0"`
Port int Port int
CertFile string `json:",optional"`
KeyFile string `json:",optional"`
Verbose bool `json:",optional"` Verbose bool `json:",optional"`
MaxConns int `json:",default=10000"` MaxConns int `json:",default=10000"`
MaxBytes int64 `json:",default=1048576,range=[0:8388608]"` MaxBytes int64 `json:",default=1048576,range=[0:8388608]"`

@ -65,7 +65,11 @@ func (s *engine) StartWithRouter(router httpx.Router) error {
return err return err
} }
if len(s.conf.CertFile) == 0 && len(s.conf.KeyFile) == 0 {
return internal.StartHttp(s.conf.Host, s.conf.Port, router) return internal.StartHttp(s.conf.Host, s.conf.Port, router)
}
return internal.StartHttps(s.conf.Host, s.conf.Port, s.conf.CertFile, s.conf.KeyFile, router)
} }
func (s *engine) appendAuthHandler(fr featuredRoutes, chain alice.Chain, func (s *engine) appendAuthHandler(fr featuredRoutes, chain alice.Chain,

Loading…
Cancel
Save