refactor: allow Routes to return an error
This commit is contained in:
parent
f34c041401
commit
7c330e308e
10
api/api.go
10
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...))
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue