diff --git a/.gitignore b/.gitignore index cb30448..c183848 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ afero-demo *.exe -go.sum \ No newline at end of file +go.sum +*.txt \ No newline at end of file diff --git a/main.go b/main.go index daec585..293eec8 100644 --- a/main.go +++ b/main.go @@ -18,4 +18,28 @@ func main() { } fmt.Println(string(data)) + + //真实文件系统 + fs = afero.NewOsFs() + + afero.WriteFile(fs, "poem.txt", []byte("月光光,照大床(文件系统)"), 0644) + + data, err = afero.ReadFile(fs, "poem.txt") + if err != nil { + panic(err) + } + + fmt.Println(string(data)) + + //拷贝文件 + err = afero.WriteFile(fs, "poem_copy.txt", data, 0644) + if err != nil { + panic(err) + } + + //限定根目录 + bfs := afero.NewBasePathFs(afero.NewOsFs(), "/home/yy/project") + if _, err := bfs.Open("/etc/passwd"); err != nil { + fmt.Println(err.Error()) + } }