oss

package module
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 3 Imported by: 3

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Object

type Object struct {
	Path             string
	Name             string
	LastModified     *time.Time
	Size             int64
	StorageInterface StorageInterface
}

Object content object

func (Object) Get

func (object Object) Get() (*os.File, error)

Get retrieve object's content

type StorageInterface

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)
	GetURL(path string) (string, error)
	GetEndpoint() string
}

StorageInterface define common API to operate storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL