-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprocess-logging.go
52 lines (40 loc) · 1.18 KB
/
process-logging.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
48
49
50
51
52
package main
import (
"bytes"
"fmt"
"os"
"path"
"path/filepath"
"text/template"
)
func processLogging(g *Generator, f *File) {
gopath := os.Getenv("GOPATH")
var buf bytes.Buffer
extra, err := template.New("extra").Parse(extras["logging"])
if err != nil {
log.Fatalf("Extra Template Parsing Error: %s", err)
}
files := []string{
filepath.Join(gopath, "src", "github.com", "ayiga", "go-kit-middlewarer", "tmpl", "logging.tmpl"),
}
tmpl, err := extra.ParseFiles(files...)
if err != nil {
log.Fatalf("Template Parse Error: %s", err)
}
convertedPath := filepath.ToSlash(f.pkg.dir)
endpointPackage := createImportWithPath(path.Join(convertedPath, "endpoint"))
basePackage := createImportWithPath(convertedPath)
for _, interf := range f.interfaces {
err := tmpl.ExecuteTemplate(&buf, "logging.tmpl", createTemplateBase(basePackage, endpointPackage, interf, f.imports))
if err != nil {
log.Fatalf("Template execution failed: %s\n", err)
}
}
filename := "middleware_gen.go"
file := openFile(filepath.Join(".", "logging"), filename)
defer file.Close()
fmt.Fprint(file, string(formatBuffer(buf, filename)))
}
func init() {
registerProcess("logging", processLogging)
}