Giter Club home page Giter Club logo

x-object-storage's Introduction

💾 x-object-storage 对象存储

西安豆芽科技有限公司

目前支持 AMS(亚马逊云存储)

拉取

go get -u github.com/xgd16/x-object-storage
go mod tidy

使用演示

package main

import (
    "os"
    "fmt"
    "github.com/xgd16/x-object-storage/disk"
    "github.com/xgd16/x-object-storage/drive"
)

func main() {
    file, err := os.Open("./file/PROJECT_README.pdf")
    if err != nil {
        panic("读取文件错误" + err.Error())
    }
    defer func() { _ = file.Close() }()

    diskObj, err := disk.New(&drive.AmsDrive{
        Region:    "***",
        SecretId:  "***",
        SecretKey: "***",
        Bucket:    "***",
    })
    if err != nil {
        panic("初始化 对象失败" + err.Error())
    }

    //fmt.Println(diskObj.PutObject(file, "test/PROJECT_README.pdf"))
    fileList, err := diskObj.GetPathList()
    if err != nil {
        panic("获取列表失败")
    }
    for _, item := range fileList {
        fmt.Println(item)
        fmt.Println(diskObj.GetObjectUrl(item.Path))
    }
}

添加兼容项目 (需要实现以下接口函数)

package main

import (
    "context"
    "os"
)

type ObjectInfoList []*ObjectInfo

type ObjectInfo struct {
    Path     string `json:"path"`
    Size     int64  `json:"size"`
    UnixTime int64  `json:"unixTime"`
    Ext      string `json:"ext"`
}

type ObjectStorage interface {
    // Init 初始化函数
    Init(ctx context.Context) (ObjectStorage, error)
    // PutObject 上传对象文件
    PutObject(file *os.File, filePath string) error
    // GetPathList 获取路径列表
    GetPathList() (ObjectInfoList, error)
    // DelObject 删除对象
    DelObject(path string) error
    // GetObjectUrl 获取对象url地址
    GetObjectUrl(path string, opt ...any) (string, error)
}

x-object-storage's People

Contributors

xgd16 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.