Giter Site home page Giter Site logo

casdoor / oss Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qor/oss

0.0 3.0 5.0 86 KB

Casdoor OSS provides Go SDK to operate files via List and CRUD for file system, public cloud object storage (like AWS S3) and MinIO, mainly used by Casdoor

Home Page: https://casdoor.org/docs/category/storage

License: MIT License

Go 100.00%
casdoor cloud-storage minio object-storage oss s3 storage

oss's Introduction

OSS

Go Report Card Go Go Reference GitHub release (latest SemVer)

Casdoor OSS aims to provide a common interface to operate files with any kinds of storages, like cloud storages, FTP, file system etc

Usage

Installation

git clone https://github.com/casdoor/oss

Create Client

Different oss providers need to provide different configuration, but we support a unit API as below to create the oss client.

func New(config *Config) (*Client, error)

The config generally includes the following information:

  • AccessID: The access ID for authentication.
  • AccessKey: The access key for authentication.
  • Bucket: The name of the bucket where the data is stored.
  • Endpoint: The endpoint for accessing the storage service.

Please note that the actual configuration may vary depending on the specific storage service being used.

Operation

Currently, QOR OSS provides support for file system, S3, Aliyun and so on, You can easily implement your own storage strategies by implementing the interface.

type StorageInterface interface {
  Get(path string) (*os.File, error)
  GetStream(path string) (io.ReadCloser, error)
  Put(path string, reader io.Reader) (*Object, error)
  Delete(path string) error
  List(path string) ([]*Object, error)
  GetEndpoint() string
  GetURL(path string) (string, error)
}

Example

Here's an example of how to use QOR OSS with S3. After initializing the s3 storage, The functions in the interface are available.

import (
  "github.com/oss/filesystem"
  "github.com/oss/s3"
  awss3 "github.com/aws/aws-sdk-go/s3"
)

func main() {
  storage := s3.New(s3.Config{AccessID: "access_id", AccessKey: "access_key", Region: "region", Bucket: "bucket", Endpoint: "cdn.getqor.com", ACL: awss3.BucketCannedACLPublicRead})
  // storage := filesystem.New("/tmp")

  // Save a reader interface into storage
  storage.Put("/sample.txt", reader)

  // Get file with path
  storage.Get("/sample.txt")

  // Get object as io.ReadCloser
  storage.GetStream("/sample.txt")

  // Delete file with path
  storage.Delete("/sample.txt")

  // List all objects under path
  storage.List("/")

  // Get Public Accessible URL (useful if current file saved privately)
  storage.GetURL("/sample.txt")
}

License

Released under the MIT License.

oss's People

Contributors

azumads avatar baihhh avatar bodhi avatar dfang avatar hsluoyz avatar jinzhu avatar leo220yuyaodog avatar owen-gxz avatar sunfmin avatar tnclong avatar zealllot avatar

Watchers

 avatar  avatar  avatar

oss's Issues

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.