-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtemplates.go
47 lines (41 loc) · 1.23 KB
/
templates.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
40
41
42
43
44
45
46
47
package main
import (
"bytes"
"text/template"
"github.com/pkg/errors"
)
var (
// IRODSConfigTemplate is the *template.Template for the iRODS config file
IRODSConfigTemplate *template.Template
)
// IRODSConfigTemplateText is the text of the template for porklock's iRODS
// config file.
const IRODSConfigTemplateText = `porklock.irods-host = {{.IRODSHost}}
porklock.irods-port = {{.IRODSPort}}
porklock.irods-user = {{.IRODSUser}}
porklock.irods-pass = {{.IRODSPass}}
porklock.irods-home = {{.IRODSBase}}
porklock.irods-zone = {{.IRODSZone}}
porklock.irods-resc = {{.IRODSResc}}
`
// IRODSConfig contains all of the values for the IRODS configuration file used
// by the porklock tool out on a HTCondor compute node.
type IRODSConfig struct {
IRODSHost string
IRODSPort string
IRODSUser string
IRODSPass string
IRODSZone string
IRODSBase string
IRODSResc string
}
// GenerateFile applies the data to the given template and returns a *bytes.Buffer
// containing the result.
func GenerateFile(t *template.Template, data interface{}) (*bytes.Buffer, error) {
var buffer bytes.Buffer
err := t.Execute(&buffer, data)
if err != nil {
return &buffer, errors.Wrapf(err, "failed to apply data to the %s template", t.Name())
}
return &buffer, err
}