Giter VIP home page Giter VIP logo

go-cos's Introduction

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:

Bucket API:

Object API:

其他功能:

go-cos's People

Contributors

codelingobot avatar jojohappy avatar lewzylu avatar mozillazg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-cos's Issues

上传文件不需要提供 Content-Length 疑问

您好

上传文件操作不再需要在特定情况下强制指定 ContentLength 了(COS 服务端新功能)。

CHANGELOG.md 里面看到这句话,请问官方文档在哪里明确说明的吗?还有就是特定情况是指什么情况?

内网的时候x509有办法吗

在内网的时候,cos会解析到内部地址,然后ca证书就有问题了
golang就会报

x509: certificate signed by unknown authority

我现在改用http了,但是官方显示的链接就是https的,万一哪天http不能用了怎么办很慌。

上传失败 unsupported protocol scheme "”

u,_:=url.Parse("http://xxx-dev-1xxx.cos.ap-xxx.myqcloud.com")
	b := &cos.BaseURL{BucketURL: u}
	client := cos.NewClient(b, &http.Client{
		Transport: &cos.AuthorizationTransport{
			SecretID: "xxx",
			SecretKey: "xxx",
		},
	})
	opt := &cos.ObjectPutOptions{
		ObjectPutHeaderOptions: &cos.ObjectPutHeaderOptions{
			ContentType: fileType,
			ContentLength:len(content),
		},
		ACLHeaderOptions: &cos.ACLHeaderOptions{
			XCosACL: "private",
		},
	}

	name := "test/objectPut.go"
	f := strings.NewReader("test")
	_, err := client.Object.Put(context.Background(), name, f, nil)
	log.Println(err)

上传失败
返回下面错误:

2019/08/25 16:50:57 Put /test%2FobjectPut.go: unsupported protocol scheme "”

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.