aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-08-13 13:49:35 -0400
committerBen Burwell <ben@benburwell.com>2019-08-13 13:49:35 -0400
commite083b1b1558dc1e97da361c505653a38bd339cef (patch)
tree15c10c0258bc42c014ccb5ca5e25e06b25290eb9
parent72339bdcf71b659846c978d14ce76dda8235ec73 (diff)
Add template variables
-rw-r--r--template.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/template.go b/template.go
index cb815a3..31d4358 100644
--- a/template.go
+++ b/template.go
@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "runtime"
"strings"
"text/template"
@@ -12,6 +13,8 @@ import (
)
type TemplateData struct {
+ OS string
+ Arch string
Hostname string
Vars map[string]interface{}
}
@@ -37,13 +40,21 @@ func lookupPassword(name string) (string, error) {
}
func getTemplateData() (*TemplateData, error) {
- var data TemplateData
vars, err := readVars()
if err != nil {
return nil, err
}
- data.Vars = vars
- return &data, nil
+ data := &TemplateData{
+ OS: runtime.GOOS,
+ Arch: runtime.GOARCH,
+ Vars: vars,
+ }
+ if host, err := os.Hostname(); err != nil {
+ return nil, err
+ } else {
+ data.Hostname = host
+ }
+ return data, nil
}
func readVars() (map[string]interface{}, error) {