Document Folder APIs and add local Visit Examples.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package goncfiles_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
goncfiles "gitea.neitzel.de/konrad/go-nc-files"
|
||||
)
|
||||
|
||||
func ExampleOpenLocal() {
|
||||
root := tTempDir()
|
||||
settings := filepath.Join(root, "settings.json")
|
||||
files := filepath.Join(root, "files")
|
||||
_ = os.MkdirAll(files, 0o755)
|
||||
|
||||
visit, err := goncfiles.OpenLocal(files, settings, "myapp", "")
|
||||
if err != nil {
|
||||
fmt.Println("err:", err)
|
||||
return
|
||||
}
|
||||
if err := visit.FS.Write("note.txt", []byte("hi")); err != nil {
|
||||
fmt.Println("write:", err)
|
||||
return
|
||||
}
|
||||
data, err := visit.FS.Read("note.txt")
|
||||
if err != nil {
|
||||
fmt.Println("read:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(visit.WorkingRel, string(data))
|
||||
// Output: myapp hi
|
||||
}
|
||||
|
||||
func ExampleLocalFolder() {
|
||||
dir := tTempDir()
|
||||
folder := goncfiles.LocalFolder(dir)
|
||||
_ = folder.Write("a.txt", []byte("x"))
|
||||
ok, _ := folder.Exists("a.txt")
|
||||
fmt.Println(ok)
|
||||
// Output: true
|
||||
}
|
||||
|
||||
// tTempDir is a tiny helper so examples stay self-contained without testing.T.
|
||||
func tTempDir() string {
|
||||
dir, err := os.MkdirTemp("", "goncfiles-example-*")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
Reference in New Issue
Block a user