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
48
49
50
51
|
package main
import (
"errors"
"os"
"path/filepath"
)
type Conf struct {
Source string
Dest string
}
func loadConf() (*Conf, error) {
source := os.Getenv("CONF_SOURCE")
info, err := os.Stat(source)
if err != nil {
return nil, err
}
if !info.IsDir() {
return nil, errors.New("CONF_SOURCE is not a directory")
}
home, err := os.UserHomeDir()
if err != nil {
return nil, err
}
return &Conf{Source: source, Dest: home}, nil
}
func (c *Conf) FileNames() ([]string, error) {
var names []string
dir := filepath.Join(c.Source, "templates")
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
name, err := filepath.Rel(dir, path)
if err != nil {
return err
}
names = append(names, name)
return nil
})
if err != nil {
return nil, err
}
return names, nil
}
|