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..ebe3a8d6 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,7 +66,8 @@ func HTTPModule() fx.Option { }, }) }), - fx.Provide(fx.Annotate(httpRouter, fx.ParamTags(``, `group:"connectorHandlers"`))), + fx.Supply(serviceInfo), + 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/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() 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