Skip to content

Commit

Permalink
Merge pull request #140 from atomist-skills/allow-handler-selection-b…
Browse files Browse the repository at this point in the history
…y-func

allow selecting a handler by func instead of just map
  • Loading branch information
chrispatrick authored Oct 18, 2024
2 parents ce62960 + 85fe287 commit 8174f72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func CreateHttpHandlerWithLogger(handlers Handlers, loggerCreator CreateLogger)
logger.Debugf("Skill execution took %d ms", time.Now().UnixMilli()-start.UnixMilli())
}()

if handle, ok := handlers[name]; ok {
if handle, ok := handlers(name); ok {
logger.Debugf("Invoking event handler '%s'", name)

err = SendStatus(ctx, req, Status{
Expand Down
9 changes: 8 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,11 @@ func (r *RequestContext) NewTransaction() Transaction {

type EventHandler func(ctx context.Context, req RequestContext) Status

type Handlers map[string]EventHandler
type Handlers func(name string) (EventHandler, bool)

func HandlersFromMap(handlers map[string]EventHandler) Handlers {
return func(name string) (EventHandler, bool) {
handle, ok := handlers[name]
return handle, ok
}
}

0 comments on commit 8174f72

Please sign in to comment.