-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
56 lines (45 loc) · 969 Bytes
/
options.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
package file
import (
"io/fs"
"strconv"
)
type options struct {
filePerm *fs.FileMode
folderPerm *fs.FileMode
fileFlag *int
}
type Option func(options *options) error
// WithFilePerm sets the file permission.
//
// The permission is a string of octal digits, such as "0644".
func WithFilePerm(filePerm string) Option {
return func(options *options) error {
if filePerm == "" {
return nil
}
perm, err := strconv.ParseUint(filePerm, 8, 32)
if err != nil {
return err
}
v := fs.FileMode(perm)
options.filePerm = &v
return nil
}
}
// WithFolderPerm sets the folder permission.
//
// The permission is a string of octal digits, such as "0755".
func WithFolderPerm(folderPerm string) Option {
return func(options *options) error {
if folderPerm == "" {
return nil
}
perm, err := strconv.ParseUint(folderPerm, 8, 32)
if err != nil {
return err
}
v := fs.FileMode(perm)
options.folderPerm = &v
return nil
}
}