-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from zuiwuchang/master
option for loader
- Loading branch information
Showing
5 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/liuzl/gocc | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d // indirect | ||
github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d h1:qSmEGTgjkESUX5kPMSGJ4pcBUtYVDdkNzMrjQyvRvp0= | ||
github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d/go.mod h1:x7SghIWwLVcJObXbjK7S2ENsT1cAcdJcPl7dRaSFog0= | ||
github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d h1:hTRDIpJ1FjS9ULJuEzu69n3qTgc18eI+ztw/pJv47hs= | ||
github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d/go.mod h1:7xD3p0XnHvJFQ3t/stEJd877CSIMkH/fACVWen5pYnc= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package gocc | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
type Loader interface { | ||
Open(filepath string) (io.ReadCloser, error) | ||
} | ||
|
||
type OSLoader struct { | ||
} | ||
|
||
func (OSLoader) Open(filepath string) (io.ReadCloser, error) { | ||
return os.Open(filepath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package gocc | ||
|
||
var defaultOptions = options{ | ||
dir: DefaultDir(), | ||
loader: OSLoader{}, | ||
} | ||
|
||
type options struct { | ||
dir string | ||
loader Loader | ||
} | ||
|
||
type Option interface { | ||
apply(*options) | ||
} | ||
|
||
type funcOption struct { | ||
f func(*options) | ||
} | ||
|
||
func (fdo *funcOption) apply(do *options) { | ||
fdo.f(do) | ||
} | ||
func newFuncOption(f func(*options)) *funcOption { | ||
return &funcOption{ | ||
f: f, | ||
} | ||
} | ||
func WithDir(dir string) Option { | ||
return newFuncOption(func(o *options) { | ||
o.dir = dir | ||
}) | ||
} | ||
func WithLoader(loader Loader) Option { | ||
return newFuncOption(func(o *options) { | ||
if loader == nil { | ||
o.loader = OSLoader{} | ||
} else { | ||
o.loader = loader | ||
} | ||
}) | ||
} |