refactor: allow Routes to return an error

This commit is contained in:
Derrick Hammer 2024-02-17 03:04:15 -05:00
parent f34c041401
commit 7c330e308e
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 9 additions and 3 deletions

View File

@ -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...))

View File

@ -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 {