@@ -31,9 +31,6 @@ type File struct {
31
31
}
32
32
33
33
func (f * File ) UniqueID () string {
34
- if f .uniqueID == "" {
35
- f .uniqueID = helpers .Md5String (f .LogicalName ())
36
- }
37
34
return f .uniqueID
38
35
}
39
36
@@ -51,18 +48,10 @@ func (f *File) BaseFileName() string {
51
48
}
52
49
53
50
func (f * File ) Section () string {
54
- if f .section != "" {
55
- return f .section
56
- }
57
- f .section = helpers .GuessSection (f .Dir ())
58
51
return f .section
59
52
}
60
53
61
54
func (f * File ) LogicalName () string {
62
- if f .logicalName != "" {
63
- return f .logicalName
64
- }
65
- _ , f .logicalName = filepath .Split (f .relpath )
66
55
return f .logicalName
67
56
}
68
57
@@ -71,18 +60,10 @@ func (f *File) SetDir(dir string) {
71
60
}
72
61
73
62
func (f * File ) Dir () string {
74
- if f .dir != "" {
75
- return f .dir
76
- }
77
- f .dir , _ = filepath .Split (f .relpath )
78
63
return f .dir
79
64
}
80
65
81
66
func (f * File ) Extension () string {
82
- if f .ext != "" {
83
- return f .ext
84
- }
85
- f .ext = strings .TrimPrefix (filepath .Ext (f .LogicalName ()), "." )
86
67
return f .ext
87
68
}
88
69
@@ -101,9 +82,17 @@ func NewFileWithContents(relpath string, content io.Reader) *File {
101
82
}
102
83
103
84
func NewFile (relpath string ) * File {
104
- return & File {
85
+ f := & File {
105
86
relpath : relpath ,
106
87
}
88
+
89
+ f .dir , _ = filepath .Split (f .relpath )
90
+ _ , f .logicalName = filepath .Split (f .relpath )
91
+ f .ext = strings .TrimPrefix (filepath .Ext (f .LogicalName ()), "." )
92
+ f .section = helpers .GuessSection (f .Dir ())
93
+ f .uniqueID = helpers .Md5String (f .LogicalName ())
94
+
95
+ return f
107
96
}
108
97
109
98
func NewFileFromAbs (base , fullpath string , content io.Reader ) (f * File , err error ) {
0 commit comments