💿 go language multi-driver storage package

  • By duxweb
  • Last update: May 26, 2023
  • Comments: 0


Version License: MIT

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


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


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


func main() {
    example := storage.New('local', map[string]string{
		"path": "./uploads",
	    "domain": "",
    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%.


👤 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