go-storage
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
- Website: https://github.com/duxweb
- Github: @duxweb
??
Contributing
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a
📝
License
Copyright © 2023 duxweb.
This project is [MIT](https://github.com/duxweb/go-storage/blob/main/LICENSE\) licensed.
This README was generated with