Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
cmd/bosun: add pct template function
Browse files Browse the repository at this point in the history
Also sort functions by name.
  • Loading branch information
maddyblue committed Jun 18, 2015
1 parent 6b35231 commit 965448b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,13 @@ var defaultFuncs = ttemplate.FuncMap{
}
return ByteSize(0), fmt.Errorf("unexpected type: %T (%v)", v, v)
},
"pct": func(i interface{}) string {
return fmt.Sprintf("%.2f%%", i)
},
"replace": strings.Replace,
"short": func(v string) string {
return strings.SplitN(v, ".", 2)[0]
},
"replace": strings.Replace,
}

func (c *Conf) loadTemplate(s *parse.SectionNode) {
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Global template functions:

* V: performs variable expansion on the argument and returns it. Needed since normal variable expansion is not done due to the `$` character being used by the Go template syntax.
* bytes: converts the string input into a human-readable number of bytes with extension KB, MB, GB, etc.
* pct: converts the argument to a percentage. For example: `{{5.1 | pct}}` -> `5.10%`.
* replace: [strings.Replace](http://golang.org/pkg/strings/#Replace)
* short: Trims the string to everything before the first period. Useful for turning a FQDN into a shortname. For example: `{{short "foo.baz.com"}}` -> `foo`.

Expand Down

0 comments on commit 965448b

Please sign in to comment.