File tree 1 file changed +27
-7
lines changed
1 file changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -26,20 +26,40 @@ type Path struct {
26
26
Sep string
27
27
}
28
28
29
- // NewPath returns a new OS path
30
- func NewPath (path string ) * Path {
31
- return NewPathAfero (path , afero .NewOsFs ())
29
+ type PathOpts func (p * Path )
30
+
31
+ func PathWithAfero (fs afero.Fs ) PathOpts {
32
+ return func (p * Path ) {
33
+ p .fs = fs
34
+ }
32
35
}
33
36
34
- // NewPathAfero returns a Path object with the given Afero object
35
- func NewPathAfero (path string , fs afero.Fs ) * Path {
36
- return & Path {
37
+ func PathWithSeperator (sep string ) PathOpts {
38
+ return func (p * Path ) {
39
+ p .Sep = sep
40
+ }
41
+ }
42
+
43
+ // NewPath returns a new OS path
44
+ func NewPath (path string , opts ... PathOpts ) * Path {
45
+ p := & Path {
37
46
path : path ,
38
- fs : fs ,
47
+ fs : afero . NewOsFs () ,
39
48
DefaultFileMode : DefaultFileMode ,
40
49
DefaultDirMode : DefaultDirMode ,
41
50
Sep : string (os .PathSeparator ),
42
51
}
52
+ for _ , opt := range opts {
53
+ opt (p )
54
+ }
55
+ return p
56
+ }
57
+
58
+ // NewPathAfero returns a Path object with the given Afero object
59
+ //
60
+ // Deprecated: Use the PathWithAfero option in Newpath instead.
61
+ func NewPathAfero (path string , fs afero.Fs ) * Path {
62
+ return NewPath (path , PathWithAfero (fs ))
43
63
}
44
64
45
65
// Glob returns all of the path objects matched by the given pattern
You can’t perform that action at this time.
0 commit comments