Socket
Socket
Sign inDemoInstall

github.com/mozillazg/go-cos

Package Overview
Dependencies
2
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/mozillazg/go-cos

Package cos 腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK。 封装了 V5 版本的 XML API 。 在项目的 _example 目录下有各个 API 的使用示例[1] 。 [1]: 示例文件所对应的 API 说明 https://github.com/mozillazg/go-cos#todo 备注 * SDK 不会自动设置超时时间,用户根据需要设置合适的超时时间(比如,设置 `http.Client` 的 `Timeout` 字段或者 `Transport` 字段之类的)或在需要时实现所需的超时机制(比如,通过 `context` 包实现)。 * 所有的 API 在 _example 目录下都有对应的使用示例[1](示例程序中用到的 `debug` 包只是调试用的不是必需的依赖)。 [1]: 示例文件所对应的 API 说明 https://github.com/mozillazg/go-cos#todo 默认所有 API 都是匿名访问. 如果想添加认证信息的话,可以通过自定义一个 http.Client 来添加认证信息. 比如, 使用内置的 AuthorizationTransport 来为请求增加 Authorization Header 签名信息:


Version published

Readme

Source

go-cos

腾讯云对象存储服务 COS(Cloud Object Storage) Go SDK(API 版本:V5 版本的 XML API)。

Build Status Coverage Status Go Report Card GoDoc

Install

go get -u github.com/mozillazg/go-cos

推荐使用 go mod 之类的技术指定使用的 go-cos 包版本号。

Usage

package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"

	"github.com/mozillazg/go-cos"
)

func main() {
	b, _ := cos.NewBaseURL("https://<bucket>-<appid>.cos.<region>.myqcloud.com")
	c := cos.NewClient(b, &http.Client{
		Transport: &cos.AuthorizationTransport{
			SecretID:  os.Getenv("COS_SECRETID"),
			SecretKey: os.Getenv("COS_SECRETKEY"),
		},
	})

	name := "test/hello.txt"
	resp, err := c.Object.Get(context.Background(), name, nil)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	bs, _ := ioutil.ReadAll(resp.Body)
	fmt.Printf("%s\n", string(bs))
}

备注:

  • SDK 不会自动设置超时时间,用户根据需要设置合适的超时时间(比如,设置 http.ClientTimeout 字段或者 Transport 字段之类的)或在需要时实现所需的超时机制(比如,通过 context 包实现)。
  • 所有的 API 在 _example 目录下都有对应的使用示例(示例程序中用到的 debug 包只是调试用的不是必需的依赖)。

TODO

Service API:

  • Get Service(使用示例:service/get.go

Bucket API:

Object API:

其他功能:

FAQs

Last updated on 18 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc