Skip to content

Commit

Permalink
refactor: use event type constants correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaschain committed Dec 3, 2023
1 parent 59b0b02 commit adbf509
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/command_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func replaceTokens(text string, event *ChangeEvent) string {
text = strings.ReplaceAll(text, "{type}", event.Type)
text = strings.ReplaceAll(text, "{type}", event.Type.String())
return strings.ReplaceAll(text, "{file}", event.FileName)
}

Expand Down
20 changes: 16 additions & 4 deletions core/event_types/event_types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package event_types

type EventType = string
type EventType string

var (
Create EventType = "CREATE"
Write = "WRITE"
Remove = "REMOVE"
Rename = "RENAME"
Write EventType = "WRITE"
Remove EventType = "REMOVE"
Rename EventType = "RENAME"
)

func (e EventType) IsValid() bool {
switch e {
case Create, Write, Remove, Rename:
return true
}
return false
}

func (e EventType) String() string {
return string(e)
}
2 changes: 1 addition & 1 deletion infrastructure/file_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func loop(watcher *fsnotify.Watcher, callback core.ChangeCallback) {
if !ok {
continue
}
changeEvent := core.ChangeEvent{Type: event.Op.String(), FileName: event.Name}
changeEvent := core.ChangeEvent{Type: event.Op, FileName: event.Name}

Check failure on line 17 in infrastructure/file_watcher.go

View workflow job for this annotation

GitHub Actions / Run Tests

cannot use event.Op (variable of type fsnotify.Op) as event_types.EventType value in struct literal
callback(&changeEvent, nil)
case err, _ := <-watcher.Errors:
if err != nil {
Expand Down

0 comments on commit adbf509

Please sign in to comment.