-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
43 lines (38 loc) · 959 Bytes
/
util.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
package csvlib
import (
"bytes"
"fmt"
"strings"
"text/template"
"github.com/hashicorp/go-multierror"
)
func validateHeader(header []string) error {
mapCheckUniq := make(map[string]struct{}, len(header))
for _, h := range header {
hh := strings.TrimSpace(h)
if h != hh || len(hh) == 0 {
return fmt.Errorf("%w: \"%s\" invalid", ErrHeaderColumnInvalid, h)
}
if _, ok := mapCheckUniq[hh]; ok {
return fmt.Errorf("%w: \"%s\" duplicated", ErrHeaderColumnDuplicated, h)
}
mapCheckUniq[hh] = struct{}{}
}
return nil
}
func processTemplate(templ string, params ParameterMap) (detail string, retErr error) {
detail = templ
t, err := template.New("error").Parse(detail)
if err != nil {
retErr = multierror.Append(retErr, err)
return
}
buf := bytes.NewBuffer(make([]byte, 0, 100)) //nolint:mnd
err = t.Execute(buf, params)
if err != nil {
retErr = multierror.Append(retErr, err)
} else {
detail = buf.String()
}
return
}