From 383b710eef1692b7e7dc3fd120f41a992d369882 Mon Sep 17 00:00:00 2001 From: Ragot Geoffrey Date: Fri, 16 Dec 2022 11:33:55 +0100 Subject: [PATCH 1/2] feat: add GET _/info --- cmd/server.go | 5 ++++- internal/app/api/module.go | 3 ++- internal/app/api/router.go | 10 +++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 08a0a600..b872227f 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -6,6 +6,7 @@ import ( "github.com/formancehq/go-libs/otlp/otlptraces" "github.com/bombsimon/logrusr/v3" + sharedapi "github.com/formancehq/go-libs/api" "github.com/formancehq/payments/internal/app/api" "github.com/formancehq/payments/internal/app/storage" "github.com/pkg/errors" @@ -83,7 +84,9 @@ func runServer(cmd *cobra.Command, args []string) error { return publish.NewTopicMapperPublisher(p, topicsMapping()) }, fx.As(new(publish.Publisher))))) - options = append(options, api.HTTPModule()) + options = append(options, api.HTTPModule(sharedapi.ServiceInfo{ + Version: Version, + })) options = append(options, publish.Module()) switch { diff --git a/internal/app/api/module.go b/internal/app/api/module.go index e758cec9..a4a85f8e 100644 --- a/internal/app/api/module.go +++ b/internal/app/api/module.go @@ -42,7 +42,7 @@ const ( serviceName = "Payments" ) -func HTTPModule() fx.Option { +func HTTPModule(serviceInfo api.ServiceInfo) fx.Option { return fx.Options( fx.Invoke(func(m *mux.Router, lc fx.Lifecycle) { lc.Append(fx.Hook{ @@ -66,6 +66,7 @@ func HTTPModule() fx.Option { }, }) }), + fx.Supply(serviceInfo), fx.Provide(fx.Annotate(httpRouter, fx.ParamTags(``, `group:"connectorHandlers"`))), addConnector[dummypay.Config](dummypay.NewLoader()), addConnector[modulr.Config](modulr.NewLoader()), diff --git a/internal/app/api/router.go b/internal/app/api/router.go index b1bf2022..a1e68c9b 100644 --- a/internal/app/api/router.go +++ b/internal/app/api/router.go @@ -3,18 +3,17 @@ package api import ( "net/http" - "github.com/formancehq/payments/internal/app/models" - - "github.com/formancehq/payments/internal/app/storage" - + "github.com/formancehq/go-libs/api" "github.com/formancehq/go-libs/auth" "github.com/formancehq/payments/internal/app/integration" + "github.com/formancehq/payments/internal/app/models" + "github.com/formancehq/payments/internal/app/storage" "github.com/gorilla/mux" "github.com/spf13/viper" "go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux" ) -func httpRouter(store *storage.Storage, connectorHandlers []connectorHandler) (*mux.Router, error) { +func httpRouter(store *storage.Storage, serviceInfo api.ServiceInfo, connectorHandlers []connectorHandler) (*mux.Router, error) { rootMux := mux.NewRouter() if viper.GetBool(otelTracesFlag) { @@ -27,6 +26,7 @@ func httpRouter(store *storage.Storage, connectorHandlers []connectorHandler) (* rootMux.Path("/_health").Handler(healthHandler(store)) rootMux.Path("/_live").Handler(liveHandler()) + rootMux.Path("/_info").Handler(api.InfoHandler(serviceInfo)) authGroup := rootMux.Name("authenticated").Subrouter() From 9b7d5493814342b7d38b91fdcb9c7880d71516a9 Mon Sep 17 00:00:00 2001 From: Ragot Geoffrey Date: Fri, 16 Dec 2022 11:40:11 +0100 Subject: [PATCH 2/2] feat: add GET _/info on swagger --- internal/app/api/module.go | 2 +- swagger.yml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/app/api/module.go b/internal/app/api/module.go index a4a85f8e..ebe3a8d6 100644 --- a/internal/app/api/module.go +++ b/internal/app/api/module.go @@ -67,7 +67,7 @@ func HTTPModule(serviceInfo api.ServiceInfo) fx.Option { }) }), fx.Supply(serviceInfo), - fx.Provide(fx.Annotate(httpRouter, fx.ParamTags(``, `group:"connectorHandlers"`))), + fx.Provide(fx.Annotate(httpRouter, fx.ParamTags(``, ``, `group:"connectorHandlers"`))), addConnector[dummypay.Config](dummypay.NewLoader()), addConnector[modulr.Config](modulr.NewLoader()), addConnector[stripe.Config](stripe.NewLoader()), diff --git a/swagger.yml b/swagger.yml index cf44f9f7..12d1f392 100644 --- a/swagger.yml +++ b/swagger.yml @@ -4,6 +4,17 @@ info: version: "PAYMENTS_VERSION" paths: + /_info: + get: + summary: Get server info + operationId: getServerInfo + responses: + 200: + description: Server information + content: + application/json: + schema: + $ref: '#/components/schemas/ServerInfo' /payments: get: summary: List payments @@ -986,3 +997,10 @@ components: description: The creation date of the more recent BalanceTransaction fetched from stripe for this account noMoreHistory: type: boolean + ServerInfo: + type: object + required: + - version + properties: + version: + type: string