-
Notifications
You must be signed in to change notification settings - Fork 2
/
writer.go
39 lines (32 loc) · 702 Bytes
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"io"
"strings"
"text/template"
)
// Writer contains the actions to write the contents of secrets
type Writer struct {
Path string
Writer io.Writer
Tmpl *template.Template
}
// NewWriter creates a new writer
func NewWriter(wr io.Writer, tmpl string) (*Writer, error) {
funcMap := template.FuncMap{
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
}
t, err := template.New("").Funcs(funcMap).Parse(fmt.Sprintf(tmplLoop, tmpl))
if err != nil {
return nil, err
}
return &Writer{
Writer: wr,
Tmpl: t,
}, nil
}
// Write writes the secrets in a file
func (w *Writer) Write(s ...*SecretData) error {
return w.Tmpl.Execute(w.Writer, s)
}