You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.1 KiB
62 lines
1.1 KiB
package upyun
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
version = "3.0.1"
|
|
|
|
defaultChunkSize = 32 * 1024
|
|
defaultConnectTimeout = time.Second * 60
|
|
)
|
|
|
|
type UpYunConfig struct {
|
|
Bucket string
|
|
Operator string
|
|
Password string
|
|
Secret string // deprecated
|
|
Hosts map[string]string
|
|
UserAgent string
|
|
}
|
|
|
|
type UpYun struct {
|
|
UpYunConfig
|
|
httpc *http.Client
|
|
deprecated bool
|
|
}
|
|
|
|
func NewUpYun(config *UpYunConfig) *UpYun {
|
|
up := &UpYun{}
|
|
up.Bucket = config.Bucket
|
|
up.Operator = config.Operator
|
|
up.Password = md5Str(config.Password)
|
|
up.Secret = config.Secret
|
|
up.Hosts = config.Hosts
|
|
if config.UserAgent != "" {
|
|
up.UserAgent = config.UserAgent
|
|
} else {
|
|
up.UserAgent = makeUserAgent(version)
|
|
}
|
|
|
|
up.httpc = &http.Client{
|
|
Transport: &http.Transport{
|
|
Dial: func(network, addr string) (c net.Conn, err error) {
|
|
return net.DialTimeout(network, addr, defaultConnectTimeout)
|
|
},
|
|
},
|
|
}
|
|
|
|
return up
|
|
}
|
|
|
|
func (up *UpYun) SetHTTPClient(httpc *http.Client) {
|
|
up.httpc = httpc
|
|
}
|
|
|
|
func (up *UpYun) UseDeprecatedApi() {
|
|
up.deprecated = true
|
|
}
|