r2

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 19 Imported by: 0

README

Cloudflare R2

Cloudflare R2

Usage

import "https://github.com/casdoor/oss"

func main() {
  storage := r2.New(&r2.Config{{
        AccountId:       "Cloudflare AccountId",
        AccessKeyId:      "Cloudflare R2 AccessKeyId",
        AccessKeySecret:  "Cloudflare R2 AccessKeySecret",
        Bucket:          "Cloudflare R2 Bucket",
        Endpoint:        "https://{AccountId}.r2.cloudflarestorage.com",

  // 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")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	R2     *s3.Client
	Config *Config
}

func New

func New(config *Config) *Client

New init cloudflare r2 store

func (Client) Delete

func (client Client) Delete(path string) error

Delete file with path

func (Client) Get

func (client Client) Get(path string) (file *os.File, err error)

Get file with path

func (Client) GetEndpoint

func (client Client) GetEndpoint() string

GetEndpoint string

func (Client) GetStream

func (client Client) GetStream(path string) (io.ReadCloser, error)

GetStream Get object as io.ReadCloser

func (Client) GetURL

func (client Client) GetURL(path string) (string, error)

GetURL Public Accessible URL (useful if current file saved privately)

func (Client) List

func (client Client) List(path string) ([]*oss.Object, error)

List all objects under path

func (Client) Put

func (client Client) Put(urlPath string, reader io.Reader) (*oss.Object, error)

Put Save a reader interface into storage

func (Client) ToRelativePath

func (client Client) ToRelativePath(urlPath string) string

ToRelativePath process path to relative path

type Config

type Config struct {
	AccountId       string
	AccessKeyId     string
	AccessKeySecret string
	Bucket          string
	Endpoint        string
}

Jump to

Keyboard shortcuts

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