package server import ( "github.com/go-kratos/kratos/v2/middleware/recovery" "github.com/go-kratos/kratos/v2/middleware/tracing" "github.com/go-kratos/kratos/v2/transport/http" "hilo/api/service/demo" "hilo/app/service/demo/internal/conf" "hilo/app/service/demo/internal/handler" "hilo/common/httpext" "time" ) // NewHTTPServer new a http server. func NewHTTPServer(c *conf.Server, svc *handler.DemoHandler) *http.Server { var opts = []http.ServerOption{ http.Middleware( recovery.Recovery(), tracing.Server(), ValidateParams(), ), http.ResponseEncoder(httpext.Encoder), http.ErrorEncoder(httpext.ErrorEncoder), } if c.Http.Addr != "" { opts = append(opts, http.Address(c.Http.Addr)) } if c.Http.Timeout != 0 { opts = append(opts, http.Timeout(time.Duration(c.Grpc.Timeout)*time.Second)) } srv := http.NewServer(opts...) demo.RegisterDemoHTTPServer(srv, svc) return srv }