aboutsummaryrefslogtreecommitdiff
path: root/lib/memfs/pathnode.go
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-12-09lib/memfs: add parameter withContent to [Node.JSON]Shulhan
If the parameter withContent is true, which is default in MarshalJSON, then all of the node content will be included in JSON output. This also changes the parameter withoutModTime to withModTime because working with negation make code not easy to read.
2023-11-14lib/memfs: add option to pack JSON without ModTimeShulhan
2023-09-11lib/memfs: update and add missing comment to constants and methodsShulhan
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2021-12-19lib/memfs: realign struct Node, Options, PathNode, and on unit testsShulhan
The realign save storage spaces on struct, * Node: from 240 to 224 bytes (-16 bytes) * Options: from 112 to 104 bytes (-8 bytes) * PathNode: from 16 to 8 bytes (-8 bytes)
2021-10-09lib/memfs: remove PathNode "f" fieldShulhan
Previously, the PathNode has two fields to store the node in memory, one is "v" that store map of path to *Node and another is "f" that store the map of path to function that return a *Node. The "f" is used to handle embedding Go generated code, but since the template now can handle generated dynamic path and Node this field is not used anymore.
2021-09-13lib/memfs: fix possible data race on PathNodeShulhan
During Memfs Get(), if the node returned by PathNodes.Get() is null, the memfs instance will try to refresh the directory tree. In case the requested path exist, the memfs will write to PathNodes through AddChild() At the same time, there maybe a request to access another path, which cause both read and write occured.
2021-08-29lib/memfs: change the MarshalJSON to always return an objectShulhan
Previously, MarshalJSON on memfs will return an object of map of all PathNodes and on Node it will return an object. This changes make it the JSON response consistent. If its directory it will return the node object with its childs, without "content". If its file, it will return the node object with content. While at it, use single "mod_time" with value is epoch and return the node ContentType as "content_type".
2021-08-12lib/memfs: make the MarshalJSON on Node to return the contentShulhan
Encoding the PathNode to JSON will include the content of each Node, but encoding only single Node will include the content.
2021-07-25lib/memfs: implement json.Marshaler on MemFS and NodeShulhan
Previously, without MarshalJSON, encoding the MemFS or Node object will result in incomplete information, for example, missing name, modification time, and size. This commit implement the json.Marshaler in MemFS which encode the PathNode sorted by keys in ascending order.
2019-09-23memfs: use Set instead SetFunc when generating templateShulhan
2019-04-17memfs: refactoring go generate file to use type from memfsShulhan
Previous Go generated file use their own Node and provide single function Get() to get the node based on path. This method does not work when using it directly with memfs. For example, on server that contains instance of memfs and want to use the output from GoGenerate, it would need to add their own wrapper for Get() and memfs.Get(). It should be more simple than that. This change add global variable GeneratedPathNode to memfs package, that will be set by file from go generate. If the GeneratedPathNode is not nil, memfs will use it as internal mapping of path and node.