config.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. package sdk
  15. import (
  16. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils"
  17. "net/http"
  18. "time"
  19. )
  20. type Config struct {
  21. AutoRetry bool `default:"true"`
  22. MaxRetryTime int `default:"3"`
  23. UserAgent string `default:""`
  24. Debug bool `default:"false"`
  25. Timeout time.Duration `default:""`
  26. HttpTransport *http.Transport `default:""`
  27. EnableAsync bool `default:"false"`
  28. MaxTaskQueueSize int `default:"1000"`
  29. GoRoutinePoolSize int `default:"5"`
  30. }
  31. func NewConfig() (config *Config) {
  32. config = &Config{}
  33. utils.InitStructWithDefaultTag(config)
  34. return
  35. }
  36. func (c *Config) WithTimeout(timeout time.Duration) *Config {
  37. c.Timeout = timeout
  38. return c
  39. }
  40. func (c *Config) WithAutoRetry(isAutoRetry bool) *Config {
  41. c.AutoRetry = isAutoRetry
  42. return c
  43. }
  44. func (c *Config) WithMaxRetryTime(maxRetryTime int) *Config {
  45. c.MaxRetryTime = maxRetryTime
  46. return c
  47. }
  48. func (c *Config) WithUserAgent(userAgent string) *Config {
  49. c.UserAgent = userAgent
  50. return c
  51. }
  52. func (c *Config) WithHttpTransport(httpTransport *http.Transport) *Config {
  53. c.HttpTransport = httpTransport
  54. return c
  55. }
  56. func (c *Config) WithEnableAsync(isEnableAsync bool) *Config {
  57. c.EnableAsync = isEnableAsync
  58. return c
  59. }
  60. func (c *Config) WithMaxTaskQueueSize(maxTaskQueueSize int) *Config {
  61. c.MaxTaskQueueSize = maxTaskQueueSize
  62. return c
  63. }
  64. func (c *Config) WithGoRoutinePoolSize(goRoutinePoolSize int) *Config {
  65. c.GoRoutinePoolSize = goRoutinePoolSize
  66. return c
  67. }
  68. func (c *Config) WithDebug(isDebug bool) *Config {
  69. c.Debug = isDebug
  70. return c
  71. }