Skip to content

Commit

Permalink
Add Severity#GetByName()
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab authored and julianbrost committed May 8, 2023
1 parent 16e4c1b commit 61277c4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/event/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ var severityToName = func() map[Severity]string {
return m
}()

func GetSeverityByName(sev string) (Severity, error) {
severity, ok := severityByName[sev]
if !ok {
return SeverityNone, fmt.Errorf("unknown severity %q", sev)
}

return severity, nil
}

func (s *Severity) MarshalJSON() ([]byte, error) {
if name, ok := severityToName[*s]; ok {
return json.Marshal(name)
Expand Down

0 comments on commit 61277c4

Please sign in to comment.