-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Support config timeout for AlibabaCloud OSS requests #14856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
323bdac
0c391ee
10111c0
06fd90e
dd898d4
b08b5dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,10 +35,12 @@ type OssObjectClient struct { | |||||
|
|
||||||
| // OssConfig is config for the OSS Chunk Client. | ||||||
| type OssConfig struct { | ||||||
| Bucket string `yaml:"bucket"` | ||||||
| Endpoint string `yaml:"endpoint"` | ||||||
| AccessKeyID string `yaml:"access_key_id"` | ||||||
| SecretAccessKey string `yaml:"secret_access_key"` | ||||||
| Bucket string `yaml:"bucket"` | ||||||
| Endpoint string `yaml:"endpoint"` | ||||||
| AccessKeyID string `yaml:"access_key_id"` | ||||||
| SecretAccessKey string `yaml:"secret_access_key"` | ||||||
| ConnectionTimeoutSec int64 `yaml:"conn_timeout_sec"` | ||||||
| ReadWriteTimeoutSec int64 `yaml:"read_write_timeout_sec"` | ||||||
| } | ||||||
|
|
||||||
| // RegisterFlags registers flags. | ||||||
|
|
@@ -52,11 +54,17 @@ func (cfg *OssConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { | |||||
| f.StringVar(&cfg.Endpoint, prefix+"oss.endpoint", "", "oss Endpoint to connect to.") | ||||||
| f.StringVar(&cfg.AccessKeyID, prefix+"oss.access-key-id", "", "alibabacloud Access Key ID") | ||||||
| f.StringVar(&cfg.SecretAccessKey, prefix+"oss.secret-access-key", "", "alibabacloud Secret Access Key") | ||||||
| f.Int64Var(&cfg.ConnectionTimeoutSec, prefix+"oss.conn-timeout-sec", 5, "Connection timeout in seconds") | ||||||
|
||||||
| f.Int64Var(&cfg.ReadWriteTimeoutSec, prefix+"oss.read-write-timeout-sec", 5, "Read/Write timeout in seconds") | ||||||
| } | ||||||
|
|
||||||
| // NewOssObjectClient makes a new chunk.Client that writes chunks to OSS. | ||||||
| func NewOssObjectClient(_ context.Context, cfg OssConfig) (client.ObjectClient, error) { | ||||||
| client, err := oss.New(cfg.Endpoint, cfg.AccessKeyID, cfg.SecretAccessKey) | ||||||
| var options []oss.ClientOption | ||||||
| if cfg.ConnectionTimeoutSec > 0 || cfg.ReadWriteTimeoutSec > 0 { | ||||||
|
||||||
| Timeout: httpTimeOut.ConnectTimeout, |
| c.SetReadDeadline(time.Now().Add(c.timeout)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! move value check to a separate validate function is great!
Thanks for your fast reply!
Uh oh!
There was an error while loading. Please reload this page.