| 1 | package types |
| 2 | |
| 3 | // Params is the string map used to provide additional variables to the service templates. |
| 4 | type Params map[string]string |
| 5 | |
| 6 | const ( |
| 7 | // TitleKey is the common key for the title prop. |
| 8 | TitleKey = "title" |
| 9 | // MessageKey is the common key for the message prop. |
| 10 | MessageKey = "message" |
| 11 | // LevelKey is the common key for the message level prop. |
| 12 | LevelKey = "level" |
| 13 | ) |
| 14 | |
| 15 | // Level returns the MessageLevel stored under the "level" param. |
| 16 | // |
| 17 | // Returns: |
| 18 | // - MessageLevel: the parsed level. |
| 19 | // - bool: true if the level was found and parsed successfully. |
| 20 | func (p Params) Level() (MessageLevel, bool) { |
| 21 | levelStr, found := p[LevelKey] |
| 22 | if !found { |
| 23 | return Unknown, false |
| 24 | } |
| 25 | |
| 26 | return ParseMessageLevel(levelStr) |
| 27 | } |
| 28 | |
| 29 | // SetLevel sets the "level" param to the string representation of the MessageLevel. |
| 30 | // |
| 31 | // Parameters: |
| 32 | // - level: the message level to set. |
| 33 | func (p Params) SetLevel(level MessageLevel) { |
| 34 | p[LevelKey] = level.String() |
| 35 | } |
| 36 | |
| 37 | // SetMessage sets the "message" param to the specified value. |
| 38 | // |
| 39 | // Parameters: |
| 40 | // - message: the message text to set. |
| 41 | func (p Params) SetMessage(message string) { |
| 42 | p[MessageKey] = message |
| 43 | } |
| 44 | |
| 45 | // SetTitle sets the "title" param to the specified value. |
| 46 | // |
| 47 | // Parameters: |
| 48 | // - title: the title text to set. |
| 49 | func (p Params) SetTitle(title string) { |
| 50 | p[TitleKey] = title |
| 51 | } |
| 52 | |
| 53 | // Title returns the "title" param. |
| 54 | // |
| 55 | // Returns: |
| 56 | // - string: the title value. |
| 57 | // - bool: true if the title was found. |
| 58 | func (p Params) Title() (string, bool) { |
| 59 | title, found := p[TitleKey] |
| 60 | |
| 61 | return title, found |
| 62 | } |