This commit is contained in:
xinyu 2026-02-21 14:10:22 +08:00
commit ad62d9b3e5
4 changed files with 41 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
afero-demo
*.exe
go.sum

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module myschools.me/xinyu/afero-demo
go 1.24.2
require (
github.com/spf13/afero v1.15.0 // indirect
golang.org/x/text v0.34.0 // indirect
)

21
main.go Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"fmt"
"github.com/spf13/afero"
)
func main() {
//基于内存的文件读写
fs := afero.NewMemMapFs()
afero.WriteFile(fs, "poem.txt", []byte("月光光,照大床"), 0644)
data, err := afero.ReadFile(fs, "poem.txt")
if err != nil {
panic(err)
}
fmt.Println(string(data))
}

9
readme.md Normal file
View File

@ -0,0 +1,9 @@
# afero
afero 是一个用于 Go 的文件系统抽象层,它允许你使用不同的文件系统实现来操作文件和目录。
## 安装
```bash
go get -v -u github.com/spf13/afero