From c6f5ce0bfbf5e4334878155c0e26690747c06de8 Mon Sep 17 00:00:00 2001 From: JinnyYi Date: Thu, 9 Sep 2021 10:38:23 +0800 Subject: [PATCH] docs: Update README --- README.md | 32 ++++++++++++++++++++++++++++---- generated.go | 31 +++++++++++++++++++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8293d72..11eb29b 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,37 @@ -# go-services-uss - [![Build Status](https://github.com/beyondstorage/go-service-uss/workflows/Unit%20Test/badge.svg?branch=master)](https://github.com/beyondstorage/go-service-uss/actions?query=workflow%3A%22Unit+Test%22) [![License](https://img.shields.io/badge/license-apache%20v2-blue.svg)](https://github.com/Xuanwo/storage/blob/master/LICENSE) -[![go storage dev](https://img.shields.io/matrix/go-service-uss:aos.dev.svg?server_fqdn=chat.aos.dev&label=%23go-service-uss%3Aaos.dev&logo=matrix)](https://matrix.to/#/#go-service-uss:aos.dev) +[![](https://img.shields.io/matrix/beyondstorage@go-storage:matrix.org.svg?logo=matrix)](https://matrix.to/#/#beyondstorage@go-storage:matrix.org) + +# go-services-uss -uss services support for [go-storage](https://github.com/beyondstorage/go-storage) +[UPYUN Storage Service](https://www.upyun.com/products/file-storage) support for [go-storage](https://github.com/beyondstorage/go-storage). ## Install ```go go get github.com/beyondstorage/go-service-uss/v2 ``` + +## Usage + +```go +import ( + "log" + + _ "github.com/beyondstorage/go-service-uss/v2" + "github.com/beyondstorage/go-storage/v4/services" +) + +func main() { + store, err := services.NewStoragerFromString("uss://bucket_name/path/to/workdir?credential=hmac::&endpoint=https:") + if err != nil { + log.Fatal(err) + } + + // Write data from io.Reader into hello.txt + n, err := store.Write("hello.txt", r, length) +} +``` + +- See more examples in [go-storage-example](https://github.com/beyondstorage/go-storage-example). +- Read [more docs](https://beyondstorage.io/docs/go-storage/services/uss) about go-service-uss. diff --git a/generated.go b/generated.go index f830173..810805d 100644 --- a/generated.go +++ b/generated.go @@ -94,6 +94,8 @@ var pairMap = map[string]string{ "context": "context.Context", "continuation_token": "string", "credential": "string", + "default_content_type": "string", + "default_io_callback": "func([]byte)", "default_storage_pairs": "DefaultStoragePairs", "endpoint": "string", "expire": "time.Duration", @@ -138,6 +140,10 @@ type pairStorageNew struct { WorkDir string // Enable features // Default pairs + hasDefaultContentType bool + DefaultContentType string + hasDefaultIoCallback bool + DefaultIoCallback func([]byte) } // parsePairStorageNew will parse Pair slice into *pairStorageNew @@ -186,14 +192,35 @@ func parsePairStorageNew(opts []Pair) (pairStorageNew, error) { } result.HasWorkDir = true result.WorkDir = v.Value.(string) - // Enable features - // Default pairs + // Enable features + // Default pairs + case "default_content_type": + if result.hasDefaultContentType { + continue + } + result.hasDefaultContentType = true + result.DefaultContentType = v.Value.(string) + case "default_io_callback": + if result.hasDefaultIoCallback { + continue + } + result.hasDefaultIoCallback = true + result.DefaultIoCallback = v.Value.(func([]byte)) } } // Enable features // Default pairs + if result.hasDefaultContentType { + result.HasDefaultStoragePairs = true + result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithContentType(result.DefaultContentType)) + } + if result.hasDefaultIoCallback { + result.HasDefaultStoragePairs = true + result.DefaultStoragePairs.Read = append(result.DefaultStoragePairs.Read, WithIoCallback(result.DefaultIoCallback)) + result.DefaultStoragePairs.Write = append(result.DefaultStoragePairs.Write, WithIoCallback(result.DefaultIoCallback)) + } if !result.HasCredential { return pairStorageNew{}, services.PairRequiredError{Keys: []string{"credential"}} diff --git a/go.mod b/go.mod index c6d9757..1d390fb 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/beyondstorage/go-service-uss/v2 go 1.15 require ( - github.com/beyondstorage/go-storage/v4 v4.6.0 + github.com/beyondstorage/go-storage/v4 v4.7.0 github.com/upyun/go-sdk/v3 v3.0.2 ) diff --git a/go.sum b/go.sum index 5840a0e..b7fbbe9 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/Xuanwo/templateutils v0.1.0 h1:WpkWOqQtIQ2vAIpJLa727DdN8WtxhUkkbDGa6UhntJY= github.com/Xuanwo/templateutils v0.1.0/go.mod h1:OdE0DJ+CJxDBq6psX5DPV+gOZi8bhuHuVUpPCG++Wb8= -github.com/beyondstorage/go-storage/v4 v4.6.0 h1:a05dtbYjMZB7LrUSvVzzHwlx33B4yEmd5oQB7Itk7VY= -github.com/beyondstorage/go-storage/v4 v4.6.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= +github.com/beyondstorage/go-storage/v4 v4.7.0 h1:7hpRFNoPY0vWRSH/p2biD2dUQdZMrs1TuIkkqDefmCE= +github.com/beyondstorage/go-storage/v4 v4.7.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY= github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU= github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ=