qcloudcos

package
v0.2.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

source: https://github.com/tencentyun/cos-go-sdk-v5

Index

Constants

This section is empty.

Variables

View Source
var NeedSignHeaders = map[string]bool{
	"host":                           true,
	"range":                          true,
	"x-cos-acl":                      true,
	"x-cos-grant-read":               true,
	"x-cos-grant-write":              true,
	"x-cos-grant-full-control":       true,
	"response-content-type":          true,
	"response-content-language":      true,
	"response-expires":               true,
	"response-cache-control":         true,
	"response-content-disposition":   true,
	"response-content-encoding":      true,
	"cache-control":                  true,
	"content-disposition":            true,
	"content-encoding":               true,
	"content-type":                   true,
	"content-length":                 true,
	"content-md5":                    true,
	"transfer-encoding":              true,
	"versionid":                      true,
	"expect":                         true,
	"expires":                        true,
	"x-cos-content-sha1":             true,
	"x-cos-storage-class":            true,
	"if-match":                       true,
	"if-modified-since":              true,
	"if-none-match":                  true,
	"if-unmodified-since":            true,
	"origin":                         true,
	"access-control-request-method":  true,
	"access-control-request-headers": true,
	"x-cos-object-type":              true,
}

需要校验的 Headers 列表

Functions

func AddAuthorizationHeader

func AddAuthorizationHeader(secretID, secretKey string, sessionToken string, req *http.Request, authTime *AuthTime)

AddAuthorizationHeader 给 req 增加签名信息

func SetNeedSignHeaders

func SetNeedSignHeaders(key string, val bool)

非线程安全,只能在进程初始化(而不是Client初始化)时做设置

Types

type AuthTime

type AuthTime struct {
	SignStartTime time.Time
	SignEndTime   time.Time
	KeyStartTime  time.Time
	KeyEndTime    time.Time
}

AuthTime 用于生成签名所需的 q-sign-time 和 q-key-time 相关参数

func NewAuthTime

func NewAuthTime(expire time.Duration) *AuthTime

NewAuthTime 生成 AuthTime 的便捷函数

expire: 从现在开始多久过期.

type AuthorizationTransport

type AuthorizationTransport struct {
	SecretID     string
	SecretKey    string
	SessionToken string

	// 签名多久过期
	Expire    time.Duration
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

AuthorizationTransport 给请求增加 Authorization header

func (*AuthorizationTransport) GetCredential

func (t *AuthorizationTransport) GetCredential() (string, string, string)

GetCredential get the ak, sk, token

func (*AuthorizationTransport) RoundTrip

func (t *AuthorizationTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

func (*AuthorizationTransport) SetCredential

func (t *AuthorizationTransport) SetCredential(ak, sk, token string)

SetCredential update the SecretID(ak), SercretKey(sk), sessiontoken

type COSConfig

type COSConfig struct {
	Host      string `toml:"host" mapstructure:"host"  validate:"nonzero"`
	SecretID  string `toml:"secret_id"   mapstructure:"secret_id"   validate:"nonzero"`
	SecretKey string `toml:"secret_key"  mapstructure:"secret_key"  validate:"nonzero"`
}

type COSUploader

type COSUploader struct {
	Config COSConfig
}

func (*COSUploader) PutFile

func (u *COSUploader) PutFile(localPath, targetPath string) (err error)

func (COSUploader) Upload

func (u COSUploader) Upload(t *model.Task) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL