Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GET _/info #68

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions internal/app/api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()),
Expand Down
10 changes: 5 additions & 5 deletions internal/app/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()

Expand Down
18 changes: 18 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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