go-filesystem 文件管理器

go-filesystem 文件管理器

适配器

  • local: 本地存储

安装

go get github.com/deatil/go-filesystem

示例

import (
    "github.com/deatil/go-filesystem/filesystem"
    localAdapter "github.com/deatil/go-filesystem/filesystem/adapter/local"
)

func init() {
    // 根目录
    root := "/storage"
    adapter := localAdapter.New(root)

    // 配置
    adapterConf := make(map[string]interface{})

    // 磁盘
    fs := filesystem.New(adapter, adapterConf)

    // 使用
    fs.Write(path string, contents string) bool
}

常用方法

// 写入
fs.Write(path, contents string) bool

// 添加数据
fs.Put(path, contents string) bool

// 读取后删除
fs.ReadAndDelete(path string) (interface{}, error)

// 更新
fs.Update(path, contents string) bool

// 读取
fs.Read(path string) interface{}

// 重命名
fs.Rename(path, newpath string) bool

// 复制
fs.Copy(path, newpath string) bool

// 删除
fs.Delete(path string) bool

// 删除文件夹
fs.DeleteDir(dirname string) bool

// 创建文件夹
fs.CreateDir(dirname string) bool

// 列出内容
fs.ListContents(dirname string) bool

相关推荐

通用后台管理系统: lakego-admin

本作品采用《CC 协议》,转载必须注明作者和本文链接
我们走了很远的路,终于发现,路已经不止一条
讨论数量: 2
qbhy

很棒。另外 goal 也实现了 filesystem 哦 github.com/goal-web/filesystem

2年前 评论
deatil (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!