From 7c330e308ebaff9f115cc36949d223c277eb3cb0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 17 Feb 2024 03:04:15 -0500 Subject: [PATCH] refactor: allow Routes to return an error --- api/api.go | 10 ++++++++-- api/registry/registry.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/api.go b/api/api.go index eb6af0e..b8659d3 100644 --- a/api/api.go +++ b/api/api.go @@ -44,10 +44,16 @@ func BuildApis(config *viper.Viper) fx.Option { return nil })) - options = append(options, fx.Invoke(func(protocols []registry.API) { + options = append(options, fx.Invoke(func(protocols []registry.API) error { for _, protocol := range protocols { - middleware.RegisterProtocolSubdomain(config, protocol.Routes(), protocol.Name()) + routes, err := protocol.Routes() + if err != nil { + return err + } + middleware.RegisterProtocolSubdomain(config, routes, protocol.Name()) } + + return nil })) return fx.Module("api", fx.Options(options...)) diff --git a/api/registry/registry.go b/api/registry/registry.go index 951b7e0..4820057 100644 --- a/api/registry/registry.go +++ b/api/registry/registry.go @@ -14,7 +14,7 @@ type API interface { Init() error Start(ctx context.Context) error Stop(ctx context.Context) error - Routes() *httprouter.Router + Routes() (*httprouter.Router, error) } type APIEntry struct {