-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompile.go
57 lines (47 loc) · 966 Bytes
/
compile.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
53
54
55
56
57
package main
import (
"os"
"strings"
"io/fs"
"path/filepath"
"text/template"
)
func (opt *options) compile(path string, d fs.DirEntry) error {
dest := filepath.Join(opt.tmp, "src")
os.Mkdir(dest, os.ModePerm)
dest = filepath.Join(dest, strings.Replace(path, "docx", opt.name, -1))
fdir := filepath.Join("res", path)
if d.IsDir() {
os.Mkdir(dest, os.ModePerm)
} else {
b, err := fs.ReadFile(res, fdir)
if err != nil {
return err
}
f, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE, os.ModePerm)
if err != nil {
return err
}
defer f.Close()
if strings.Contains(path, "document.xml.rels") {
tpl, err := template.ParseFS(res, fdir)
if err != nil {
return err
}
data := map[string]interface{}{
"LHOST": opt.host,
"LPORT": opt.port,
}
err = tpl.Execute(f, data)
if err != nil {
return err
}
} else {
_, err = f.Write(b)
if err != nil {
return err
}
}
}
return nil
}