Skip to content

Commit

Permalink
refactor: move the actor map into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
nobe4 committed May 18, 2024
1 parent 0b7cb53 commit b6ac240
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 1 addition & 7 deletions cmd/gh-not/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,12 @@ func main() {

fmt.Println(allNotifications.ToString())

actorsMap := map[string]actors.Actor{
"debug": &actors.DebugActor{},
"print": &actors.PrintActor{},
"hide": &actors.HideActor{},
}

config, err := config.New("config.json")
if err != nil {
panic(err)
}

allNotifications, err = config.Apply(allNotifications, actorsMap)
allNotifications, err = config.Apply(allNotifications, actors.Map())
if err != nil {
panic(err)
}
Expand Down
10 changes: 10 additions & 0 deletions internal/actors/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"github.com/nobe4/gh-not/internal/notifications"
)

type ActorsMap map[string]Actor

func Map() ActorsMap {
return map[string]Actor{
"debug": &DebugActor{},
"print": &PrintActor{},
"hide": &HideActor{},
}
}

type Actor interface {
Run(notifications.Notification) (notifications.Notification, error)
}
Expand Down

0 comments on commit b6ac240

Please sign in to comment.