Skip to content

Commit

Permalink
Forward potential errors from registerStaticReceiverProxy up through
Browse files Browse the repository at this point in the history
RegisterUseCase.

These errors are currently always API misuse, but it might be nice to
extend RegisterUseCase to allow returning errors anyway.
  • Loading branch information
sthelen-enqs committed Oct 28, 2024
1 parent 7abed76 commit b8520bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
33 changes: 27 additions & 6 deletions cmd/remote/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
"github.com/enbility/eebus-go/api"
"github.com/enbility/eebus-go/usecases/cem/evcc"
"github.com/enbility/eebus-go/usecases/cem/evsecc"
"github.com/enbility/eebus-go/usecases/eg/lpc"
cslpc "github.com/enbility/eebus-go/usecases/cs/lpc"
eglpc "github.com/enbility/eebus-go/usecases/eg/lpc"
"github.com/enbility/eebus-go/usecases/ma/mpc"
shipapi "github.com/enbility/ship-go/api"
"github.com/enbility/ship-go/cert"
Expand Down Expand Up @@ -111,18 +112,38 @@ func main() {
log.Fatal(err)
}

r.RegisterUseCase(model.EntityTypeTypeCEM, "EG-LPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {
return lpc.NewLPC(localEntity, eventCB)
})

Check failure on line 115 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ) after top level declaration
r.RegisterUseCase(model.EntityTypeTypeCEM, "MA-MPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {
if err != nil {
log.Fatal(err)
}

err = r.RegisterUseCase(model.EntityTypeTypeCEM, "EG-LPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {

Check failure on line 120 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

method has multiple receivers

Check failure on line 120 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ., expected (
return eglpc.NewLPC(localEntity, eventCB)
})

Check failure on line 122 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: non-declaration statement outside function body
if err != nil {
log.Fatal(err)
}

err = r.RegisterUseCase(model.EntityTypeTypeCEM, "MA-MPC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {

Check failure on line 127 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

method has multiple receivers

Check failure on line 127 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ., expected (
return mpc.NewMPC(localEntity, eventCB)
})

Check failure on line 129 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: non-declaration statement outside function body
r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVCC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {
if err != nil {
log.Fatal(err)
}

err = r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVCC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {

Check failure on line 134 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

method has multiple receivers

Check failure on line 134 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: unexpected ., expected (
return evcc.NewEVCC(r.service, localEntity, eventCB)
})

Check failure on line 136 in cmd/remote/main.go

View workflow job for this annotation

GitHub Actions / Build

syntax error: non-declaration statement outside function body
r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVSECC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {
if err != nil {
log.Fatal(err)
}

err = r.RegisterUseCase(model.EntityTypeTypeCEM, "CEM-EVSECC", func(localEntity spineapi.EntityLocalInterface, eventCB api.EntityEventCallback) api.UseCaseInterface {
return evsecc.NewEVSECC(localEntity, eventCB)
})
if err != nil {
log.Fatal(err)
}

ctx, cancelCtx := context.WithCancel(context.Background())
if err = r.Listen(ctx, "tcp", net.JoinHostPort("::", strconv.Itoa(3393))); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/remote/ucs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (

type UseCaseBuilder func(spineapi.EntityLocalInterface, api.EntityEventCallback) api.UseCaseInterface

func (r *Remote) RegisterUseCase(entityType model.EntityTypeType, usecaseId string, builder UseCaseBuilder) {
func (r *Remote) RegisterUseCase(entityType model.EntityTypeType, usecaseId string, builder UseCaseBuilder) error {
// entityType/uc
var identifier UseCaseId = UseCaseId(fmt.Sprintf("%s/%s", entityType, usecaseId))

Expand All @@ -33,7 +33,7 @@ func (r *Remote) RegisterUseCase(entityType model.EntityTypeType, usecaseId stri
})
r.service.AddUseCase(uc)

r.registerStaticReceiverProxy(usecaseId, uc)
return r.registerStaticReceiverProxy(usecaseId, uc)
}

func (r *Remote) PropagateEvent(
Expand Down

0 comments on commit b8520bf

Please sign in to comment.