config.go 2.3 KB

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