-
Notifications
You must be signed in to change notification settings - Fork 25
/
asset.go
63 lines (54 loc) · 1.41 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
// 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 (
"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.
funcName 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 == '/' || r == '.' {
up = true
}
}
return out
}
// newAsset will create, initialize, and return new asset based on file
// path or real path if its symlink.
func newAsset(cfg *Config, path, name, realPath string, fi os.FileInfo) (ast *asset) {
ast = &asset{
path: path,
name: filepath.ToSlash(name),
fi: fi,
}
if len(realPath) == 0 {
ast.funcName = cfg.AssetPrefix + normalize(name)
} else {
ast.funcName = cfg.AssetPrefix + normalize(realPath)
}
return ast
}