Files
opencloud/graph-explorer/pkg/server/http/server.go
David Christofas 3bc60510ce use go-chi middlewares
go-chi already delivers the middlewares we need so we don't need to import other libraries for that.
2021-08-12 17:14:41 +02:00

57 lines
1.3 KiB
Go

package http
import (
"github.com/asim/go-micro/v3"
chimiddleware "github.com/go-chi/chi/middleware"
svc "github.com/owncloud/ocis/graph-explorer/pkg/service/v0"
"github.com/owncloud/ocis/graph-explorer/pkg/version"
"github.com/owncloud/ocis/ocis-pkg/middleware"
"github.com/owncloud/ocis/ocis-pkg/service/http"
)
// Server initializes the http service and server.
func Server(opts ...Option) (http.Service, error) {
options := newOptions(opts...)
service := http.NewService(
http.Logger(options.Logger),
http.Namespace(options.Namespace),
http.Name("graph-explorer"),
http.Version(version.String),
http.Address(options.Config.HTTP.Addr),
http.Context(options.Context),
http.Flags(options.Flags...),
)
handle := svc.NewService(
svc.Logger(options.Logger),
svc.Config(options.Config),
svc.Middleware(
chimiddleware.RealIP,
chimiddleware.RequestID,
middleware.NoCache,
middleware.Cors,
middleware.Secure,
middleware.Version(
"graph-explorer",
version.String,
),
middleware.Logger(
options.Logger,
),
),
)
{
handle = svc.NewInstrument(handle, options.Metrics)
handle = svc.NewLogging(handle, options.Logger)
handle = svc.NewTracing(handle)
}
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
return http.Service{}, err
}
return service, nil
}