config.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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) WithDebug(isDebug bool) (*Config) {
  41. c.Debug = isDebug
  42. return c
  43. }