1/* 2 * Licensed under the Apache License, Version 2.0 (the "License"); 3 * you may not use this file except in compliance with the License. 4 * You may obtain a copy of the License at 5 * 6 * http://www.apache.org/licenses/LICENSE-2.0 7 * 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15package sdk 16 17import ( 18 "net/http" 19 "time" 20 21 "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" 22) 23 24type Config struct { 25 AutoRetry bool `default:"true"` 26 MaxRetryTime int `default:"3"` 27 UserAgent string `default:""` 28 Debug bool `default:"false"` 29 Timeout time.Duration `default:"10000000000"` 30 HttpTransport *http.Transport `default:""` 31 EnableAsync bool `default:"false"` 32 MaxTaskQueueSize int `default:"1000"` 33 GoRoutinePoolSize int `default:"5"` 34 Scheme string `default:"HTTP"` 35} 36 37func NewConfig() (config *Config) { 38 config = &Config{} 39 utils.InitStructWithDefaultTag(config) 40 return 41} 42 43func (c *Config) WithAutoRetry(isAutoRetry bool) *Config { 44 c.AutoRetry = isAutoRetry 45 return c 46} 47 48func (c *Config) WithMaxRetryTime(maxRetryTime int) *Config { 49 c.MaxRetryTime = maxRetryTime 50 return c 51} 52 53func (c *Config) WithUserAgent(userAgent string) *Config { 54 c.UserAgent = userAgent 55 return c 56} 57 58func (c *Config) WithDebug(isDebug bool) *Config { 59 c.Debug = isDebug 60 return c 61} 62 63func (c *Config) WithTimeout(timeout time.Duration) *Config { 64 c.Timeout = timeout 65 return c 66} 67 68func (c *Config) WithHttpTransport(httpTransport *http.Transport) *Config { 69 c.HttpTransport = httpTransport 70 return c 71} 72 73func (c *Config) WithEnableAsync(isEnableAsync bool) *Config { 74 c.EnableAsync = isEnableAsync 75 return c 76} 77 78func (c *Config) WithMaxTaskQueueSize(maxTaskQueueSize int) *Config { 79 c.MaxTaskQueueSize = maxTaskQueueSize 80 return c 81} 82 83func (c *Config) WithGoRoutinePoolSize(goRoutinePoolSize int) *Config { 84 c.GoRoutinePoolSize = goRoutinePoolSize 85 return c 86} 87 88func (c *Config) WithScheme(scheme string) *Config { 89 c.Scheme = scheme 90 return c 91} 92