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

73 lines
1.9 KiB
Go
Raw Normal View History

2019-12-04 17:15:11 +01:00
package http
import (
2022-04-05 18:35:50 +02:00
"github.com/cs3org/reva/v2/pkg/events/server"
2021-08-24 17:48:37 +02:00
chimiddleware "github.com/go-chi/chi/v5/middleware"
2022-04-19 09:44:47 +02:00
"github.com/go-micro/plugins/v4/events/natsjs"
2022-04-12 10:13:21 +02:00
graphMiddleware "github.com/owncloud/ocis/extensions/graph/pkg/middleware"
svc "github.com/owncloud/ocis/extensions/graph/pkg/service/v0"
2021-07-09 15:15:20 +00:00
"github.com/owncloud/ocis/ocis-pkg/account"
2021-02-16 13:55:34 +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"
2022-04-05 18:35:50 +02:00
"github.com/pkg/errors"
2021-10-12 17:29:33 +02:00
"go-micro.dev/v4"
2019-12-04 17:15:11 +01:00
)
2019-12-06 13:14:21 +01:00
// Server initializes the http service and server.
func Server(opts ...Option) (http.Service, error) {
options := newOptions(opts...)
2019-12-05 16:13:39 +01:00
2019-12-06 13:14:21 +01:00
service := http.NewService(
http.Logger(options.Logger),
2019-12-27 13:09:27 +01:00
http.Namespace(options.Config.HTTP.Namespace),
2019-12-06 13:14:21 +01:00
http.Name("graph"),
http.Version(version.String),
http.Address(options.Config.HTTP.Addr),
http.Context(options.Context),
2019-12-11 16:08:24 +01:00
http.Flags(options.Flags...),
2019-12-06 13:14:21 +01:00
)
2019-12-05 17:27:47 +01:00
2022-04-05 18:35:50 +02:00
publisher, err := server.NewNatsStream(
natsjs.Address(options.Config.Events.Endpoint),
natsjs.ClusterID(options.Config.Events.Cluster),
)
if err != nil {
options.Logger.Error().
Err(err).
Msg("Error initializing events publisher")
return http.Service{}, errors.Wrap(err, "could not initialize events publisher")
}
2019-12-06 13:14:21 +01:00
handle := svc.NewService(
svc.Logger(options.Logger),
svc.Config(options.Config),
svc.Middleware(
2021-08-12 17:14:41 +02:00
chimiddleware.RequestID,
2019-12-06 13:14:21 +01:00
middleware.Version(
"graph",
version.String,
),
middleware.Logger(
options.Logger,
),
2021-07-09 15:15:20 +00:00
graphMiddleware.Auth(
account.Logger(options.Logger),
account.JWTSecret(options.Config.TokenManager.JWTSecret),
2019-12-10 14:48:28 +01:00
),
2019-12-06 13:14:21 +01:00
),
2022-04-05 18:35:50 +02:00
svc.EventsPublisher(publisher),
2019-12-05 17:27:47 +01:00
)
2019-12-06 13:14:21 +01:00
{
handle = svc.NewInstrument(handle, options.Metrics)
handle = svc.NewLogging(handle, options.Logger)
handle = svc.NewTracing(handle)
2019-12-05 17:27:47 +01:00
}
2019-12-04 17:15:11 +01:00
2021-02-25 15:53:46 +01:00
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
return http.Service{}, err
}
2019-12-04 17:15:11 +01:00
return service, nil
}