-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.go
38 lines (32 loc) · 776 Bytes
/
parse.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
package tmplnator
import (
"fmt"
l "github.com/Sirupsen/logrus"
"github.com/spf13/afero"
)
type FileParser int
func (f FileParser) String() string {
return fmt.Sprintf("Parser (%d)", f)
}
func (f FileParser) parseTemplates(done <-chan struct{}, fs afero.Fs, files ...*File) <-chan *File {
out := make(chan *File)
l.Debugf("START: %v", f)
go func() {
defer close(out)
defer l.Debugf("%v: Exiting", f)
for _, file := range files {
l.Debugf("%v: Parsing %q.", f, file.TemplateName())
if err := ParseTemplate(file, srcFs); err != nil {
l.Errorf("%v: Failed to parse %q: %v", f, file.TemplateName(), err)
continue
}
select {
case out <- file:
l.Debugf("%v: Emitting %v", f, file)
case <-done:
return
}
}
}()
return out
}