-
Notifications
You must be signed in to change notification settings - Fork 25
/
translate_common.go
67 lines (55 loc) · 1.31 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
// Copyright 2018 The go-bindata Authors. All rights reserved.
// Use of this source code is governed by a CC0 1.0 Universal (CC0 1.0)
// Public Domain Dedication license that can be found in the LICENSE file.
package bindata
import (
"bufio"
"fmt"
"io"
)
func writeHeader(bfd io.Writer, c *Config, keys []string, toc map[string]*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 err
}
if c.Split {
_, err = fmt.Fprint(bfd, "// -- Common file --\n")
if err != nil {
return err
}
} else {
_, err = fmt.Fprint(bfd, "// sources:\n")
if err != nil {
return err
}
for _, key := range keys {
asset := toc[key]
_, err = fmt.Fprintf(bfd, "// %s\n", asset.path)
if err != nil {
return err
}
}
}
// Write build tags, if applicable.
if len(c.Tags) > 0 {
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil {
return err
}
}
return nil
}
// 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
}