storage

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 3 Imported by: 1

README

go-storage

Version

This is a local, qiniu, cos, oss, obs file storage integration library

Install

go get -u github.com/duxweb/go-storage

Usage

import "github.com/duxweb/go-storage"

Example

func main() {
    example := storage.New('local', map[string]string{
		"path": "./uploads",
	    "domain": "http://0.0.0.0:8080/uploads",
    })
    example.Write(context.Background(), "example.txt", "hello world!", map[string]any)
}

Implemented methods

  • New()
  • Write()
  • WriteStream()
  • Read()
  • ReadStream()
  • Delete()
  • PublicUrl()
  • PrivateUrl()

Creation method

New returns new storage with handlers.

The supported types are as follows:

  • local
  • qiniu
  • cos
  • oss
  • obs

Please configure according to the driver type.

example := storage.New('local', map[string]string{ ... })

Some drivers have optional write configurations that can be passed according to your needs.

example.Write(ctx context.Context, path string, contents string, config map[string]any) error
example.WriteStream(ctx context.Context, path string, stream io.Reader, config map[string]any) error
example.Read(ctx context.Context, path string) (string, error)
example.ReadStream(ctx context.Context, path string) (io.Reader, error)
example.Delete(ctx context.Context, path string) error
example.PublicUrl(ctx context.Context, path string) (string, error)

Some drivers do not support private links, so they will return public links instead.

example.PrivateUrl(ctx context.Context, path string) (string, error)

Run tests

You need to modify and configure the driver data

go test

Test Coverage Report

The following table shows the test coverage results for this project:

Package Statements Coverage
github.com/duxweb/go-storage/main.go 9.61,11.14 100%
github.com/duxweb/go-storage/main.go 12.15,14.8 100%
github.com/duxweb/go-storage/main.go 15.15,17.8 100%
github.com/duxweb/go-storage/main.go 18.13,20.8 100%
github.com/duxweb/go-storage/main.go 21.13,23.8 100%
github.com/duxweb/go-storage/main.go 25.2,25.15 100%

The overall test coverage for this project is 100%.

Author

👤 duxweb

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2023 duxweb.
This project is [MIT](https://github.com/duxweb/go-storage/blob/main/LICENSE) licensed.


This README was generated with ❤️ by readme-md-generator

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStorage

type FileStorage interface {
	//Write writes content to a file
	Write(ctx context.Context, path string, contents string, config map[string]any) error
	// WriteStream writes the data stream to a file
	WriteStream(ctx context.Context, path string, stream io.Reader, config map[string]any) error
	// Read a file to a string
	Read(ctx context.Context, path string) (string, error)
	// ReadStream read the file to the stream
	ReadStream(ctx context.Context, path string) (io.Reader, error)
	// Delete delete file
	Delete(ctx context.Context, path string) error
	// PublicUrl gets the file public link
	PublicUrl(ctx context.Context, path string) (string, error)
	//PrivateUrl sets the file private link
	PrivateUrl(ctx context.Context, path string) (string, error)
}

func New

func New(Type string, config map[string]string) FileStorage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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