Skip to content

Instantly share code, notes, and snippets.

@LandonTClipp
Created September 7, 2020 20:50
Show Gist options
  • Save LandonTClipp/8a964a34fa6cb3d0cedb547cfe7a7d29 to your computer and use it in GitHub Desktop.
Save LandonTClipp/8a964a34fa6cb3d0cedb547cfe7a7d29 to your computer and use it in GitHub Desktop.
github.com/chigopher/pathlib in-memory example
package main
import (
"fmt"
"os"
"github.com/chigopher/pathlib"
"github.com/spf13/afero"
)
func main() {
// Create a path using an in-memory filesystem
path := pathlib.NewPathAfero("/", afero.NewMemMapFs())
hello := path.Join("hello_world.txt")
hello.WriteFile([]byte("hello world!"), 0o644)
subpaths, err := path.ReadDir()
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
for _, subpath := range subpaths {
fmt.Printf("Name: %s Mode: %o Size: %d\n", subpath.Name(), subpath.Mode(), subpath.Size())
}
bytes, _ := hello.ReadFile()
fmt.Println(string(bytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment