Skip to content

Commit

Permalink
Document all exported types, functions and variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
free committed Nov 1, 2017
1 parent a7143a8 commit 1306d62
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/jiralert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
listenAddress = flag.String("listen-address", ":9097", "The address to listen on for HTTP requests.")
configFile = flag.String("config", "config/jiralert.yml", "The JIRAlert configuration file")

// Build version, set by make to latest git tag via `-ldflags "-X main.Version=$(VERSION)"`.
Version = "<local build>"
)

Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func resolveFilepaths(baseDir string, cfg *Config) {
cfg.Template = join(cfg.Template)
}

// ReceiverConfig is the configuration for one receiver. It has a unique name and includes API access fields (URL, user
// and password) and issue fields (required -- e.g. project, issue type -- and optional -- e.g. priority).
type ReceiverConfig struct {
Name string `yaml:"name" json:"name"`

Expand Down
2 changes: 2 additions & 0 deletions notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
"github.com/trivago/tgo/tcontainer"
)

// Receiver wraps a JIRA client corresponding to a specific Alertmanager receiver, with its configuration and templates.
type Receiver struct {
conf *ReceiverConfig
tmpl *Template
client *jira.Client
}

// NewReceiver creates a Receiver using the provided configuration and template.
func NewReceiver(c *ReceiverConfig, t *Template) (*Receiver, error) {
client, err := jira.NewClient(http.DefaultClient, c.APIURL)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
log "github.com/golang/glog"
)

// Template wraps a text template and error, to make it easier to execute multiple templates and only check for errors
// once at the end (assuming one is only interested in the first error, which is usually the case).
type Template struct {
tmpl *template.Template
err error
Expand All @@ -29,6 +31,7 @@ var funcs = template.FuncMap{
},
}

// LoadTemplate reads and parses all templates defined in the given file and constructs a jiralert.Template.
func LoadTemplate(path string) (*Template, error) {
log.V(1).Infof("Loading templates from %q", path)
tmpl, err := template.New("").Option("missingkey=zero").Funcs(funcs).ParseFiles(path)
Expand All @@ -38,6 +41,9 @@ func LoadTemplate(path string) (*Template, error) {
return &Template{tmpl: tmpl}, nil
}

// Execute parses the provided text (or returns it unchanged if not a Go template), associates it with the templates
// defined in t.tmpl (so they may be referenced and used) and applies the resulting template to the specified data
// object, returning the output as a string.
func (t *Template) Execute(text string, data interface{}) string {
log.V(2).Infof("Executing template %q...", text)
if !strings.Contains(text, "{{") {
Expand Down

0 comments on commit 1306d62

Please sign in to comment.