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": "http://0.0.0.0:8080/uploads",
})
example.Write(context.Background(), "example.txt", "hello world!", map[string]any)
}
- New()
- Write()
- WriteStream()
- Read()
- ReadStream()
- Delete()
- PublicUrl()
- PrivateUrl()
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)
You need to modify and configure the driver data
go test
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
- Website: https://github.com/duxweb
- Github: @duxweb
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
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