forked from shuLhan/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset.go
69 lines (58 loc) · 1.33 KB
/
asset.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
69
// 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 (
"os"
"path/filepath"
"unicode"
)
//
// Asset holds information about a single asset to be processed.
//
type Asset struct {
// Path contains full file path.
Path string
// Name contains key used in TOC -- name by which asset is referenced.
Name string
// Function name for the procedure returning the asset contents.
Func string
// fi field contains the file information (to minimize calling os.Stat
// on the same file while processing).
fi os.FileInfo
}
func normalize(in string) (out string) {
up := true
for _, r := range in {
if unicode.IsLetter(r) || unicode.IsDigit(r) {
if up {
out += string(unicode.ToUpper(r))
up = false
} else {
out += string(r)
}
continue
}
if r == '/' {
up = true
}
}
return
}
//
// NewAsset will create, initialize, and return new asset based on file
// path and real path if its symlink.
//
func NewAsset(path, name, realPath string, fi os.FileInfo) (a Asset) {
a = Asset{
Path: path,
Name: filepath.ToSlash(name),
fi: fi,
}
if len(realPath) == 0 {
a.Func = "bindata" + normalize(name)
} else {
a.Func = "bindata" + normalize(realPath)
}
return
}