Files
ocis/extensions/graph-explorer/pkg/server/http/server.go
T

55 lines
1.3 KiB
Go
Raw Normal View History

2020-01-22 17:49:46 +01:00
package http
import (
2021-08-24 17:48:37 +02:00
chimiddleware "github.com/go-chi/chi/v5/middleware"
2022-04-12 10:18:35 +02:00
svc "github.com/owncloud/ocis/extensions/graph-explorer/pkg/service/v0"
2021-02-16 13:55:12 +01:00
"github.com/owncloud/ocis/ocis-pkg/middleware"
"github.com/owncloud/ocis/ocis-pkg/service/http"
2021-10-05 12:39:31 +02:00
"github.com/owncloud/ocis/ocis-pkg/version"
2021-10-12 17:29:33 +02:00
"go-micro.dev/v4"
2020-01-22 17:49:46 +01:00
)
// 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(
2021-08-12 17:14:41 +02:00
chimiddleware.RealIP,
chimiddleware.RequestID,
2021-02-16 13:55:12 +01:00
middleware.NoCache,
2020-01-22 17:49:46 +01:00
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)
}
2021-02-24 14:04:05 +01:00
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
return http.Service{}, err
}
2020-01-22 17:49:46 +01:00
return service, nil
}