config.go 2.3 KB

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