-
Notifications
You must be signed in to change notification settings - Fork 4
/
file.go
39 lines (32 loc) · 995 Bytes
/
file.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
package file
import (
"path/filepath"
"projectforge.dev/projectforge/app/lib/filesystem"
"projectforge.dev/projectforge/app/util"
)
type File struct {
Type Type `json:"type"`
Path []string `json:"path,omitempty"`
Name string `json:"name"`
Mode filesystem.FileMode `json:"mode,omitempty"`
Content string `json:"-"`
}
func NewFile(path string, mode filesystem.FileMode, b []byte, addHeader bool, pkg string, logger util.Logger) *File {
p, n := util.StringSplitPath(path)
t := getType(n)
c := string(b)
if addHeader {
c = contentWithHeader(path, t, c, util.StringDetectLinebreak(c), pkg, logger)
}
return &File{Type: t, Path: util.StringSplitPathAndTrim(p), Name: n, Mode: mode, Content: c}
}
func (f *File) FullPath() string {
return filepath.Join(filepath.Join(f.Path...), f.Name)
}
func (f *File) Ext() string {
return util.StringSplitLastOnly(f.Name, '.', true)
}
const (
prefix = "$PF_"
suffix = "$"
)