summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-07-07 19:38:50 +0700
committerShulhan <ms@kilabit.info>2022-07-09 14:21:57 +0700
commita39d5d2246f8a382776b0befa3d925efcd3a14a4 (patch)
treebcb9de36b700afe8ac2be6276d32e9d85b3f269f
parenta0689d4cb2f23033e7c984a7d7a66087c157542e (diff)
downloadpakakeh.go-a39d5d2246f8a382776b0befa3d925efcd3a14a4.tar.xz
lib/memfs: rename Option field Development to TryDirect
This changes the usage of Development flag. TryDirect define a flag to bypass file in memory. If its true, any call to Get will try direct read to file system. This flag has several use cases. First, to test serving file system directly from disk during development. Second, to combine embedded MemFS instance with non-embedded instance. One is reading content from memory, one is reading content from disk directly.
-rw-r--r--lib/http/http_test.go2
-rw-r--r--lib/memfs/memfs.go6
-rw-r--r--lib/memfs/options.go14
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/http/http_test.go b/lib/http/http_test.go
index 71633227..42bd0aa6 100644
--- a/lib/http/http_test.go
+++ b/lib/http/http_test.go
@@ -55,7 +55,7 @@ func TestMain(m *testing.M) {
Opts: &memfs.Options{
Root: "./testdata",
MaxFileSize: 30,
- Development: true,
+ TryDirect: true,
},
},
HandleFS: handleFS,
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go
index ed44000e..c55311bd 100644
--- a/lib/memfs/memfs.go
+++ b/lib/memfs/memfs.go
@@ -229,7 +229,7 @@ func (mfs *MemFS) Get(path string) (node *Node, err error) {
node = mfs.PathNodes.Get(path)
if node == nil {
- if mfs.Opts.Development {
+ if mfs.Opts.TryDirect {
node, err = mfs.refresh(path)
if err != nil {
return nil, fmt.Errorf("%s: %s: %w", logp, path, err)
@@ -239,11 +239,11 @@ func (mfs *MemFS) Get(path string) (node *Node, err error) {
return nil, os.ErrNotExist
}
- if mfs.Opts.Development {
+ if mfs.Opts.TryDirect {
_ = node.Update(nil, mfs.Opts.MaxFileSize)
// Ignore error if the file is not exist in storage.
// Use case: the node maybe have been result of embed and the
- // merged with other MemFS instance that use Development flag.
+ // merged with other MemFS instance that use TryDirect flag.
}
return node, nil
diff --git a/lib/memfs/options.go b/lib/memfs/options.go
index c4e11bd7..cae701b2 100644
--- a/lib/memfs/options.go
+++ b/lib/memfs/options.go
@@ -31,10 +31,16 @@ type Options struct {
// memory, the MemFS will behave as directory tree.
MaxFileSize int64
- // Development define a flag to bypass file in memory.
- // If its true, any call to Get will result in direct read to file
- // system.
- Development bool
+ // TryDirect define a flag to bypass file in memory.
+ // If its true, any call to Get will try direct read to file system.
+ // This flag has several use cases.
+ // First, to test serving file system directly from disk during
+ // development.
+ // Second, to combine embedded MemFS instance with non-embedded
+ // instance.
+ // One is reading content from memory, one is reading content from
+ // disk directly.
+ TryDirect bool
}
// init initialize the options with default value.