forked from shuLhan/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate_common.go
68 lines (56 loc) · 1.22 KB
/
translate_common.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
58
59
60
61
62
63
64
65
66
67
68
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain
// Dedication license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package bindata
import (
"bufio"
"fmt"
"io"
)
func writeHeader(bfd io.Writer, c *Config, toc []Asset) (err error) {
// Write the header. This makes e.g. Github ignore diffs in generated files.
_, err = fmt.Fprint(bfd, headerGeneratedBy)
if err != nil {
return
}
if c.Split {
_, err = fmt.Fprint(bfd, "// -- Common file --\n")
if err != nil {
return
}
} else {
_, err = fmt.Fprint(bfd, "// sources:\n")
if err != nil {
return
}
for _, asset := range toc {
_, err = fmt.Fprintf(bfd, "// %s\n", asset.Path)
if err != nil {
return
}
}
}
// Write build tags, if applicable.
if len(c.Tags) > 0 {
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil {
return
}
}
return
}
//
// flushAndClose will flush the buffered writer `bfd` and close the file `fd`.
//
func flushAndClose(fd io.Closer, bfd *bufio.Writer, errParam error) (err error) {
err = errParam
if err == nil {
err = bfd.Flush()
}
errClose := fd.Close()
if errClose != nil {
if err == nil {
err = errClose
}
}
return
}