gateway.go 758 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package gateway
  2. import "git.sxidc.com/go-tools/utils/http_client"
  3. type Gateway struct {
  4. httpClient *http_client.Client
  5. options *Options
  6. }
  7. func NewGateway(opts ...Option) *Gateway {
  8. options := new(Options)
  9. for _, opt := range opts {
  10. opt(options)
  11. }
  12. if options.timeoutSec == 0 {
  13. options.timeoutSec = 30
  14. }
  15. return &Gateway{
  16. httpClient: http_client.New(),
  17. options: options,
  18. }
  19. }
  20. func DestroyGateway(gateway *Gateway) {
  21. if gateway == nil {
  22. return
  23. }
  24. http_client.Destroy(gateway.httpClient)
  25. gateway.httpClient = nil
  26. gateway = nil
  27. }
  28. type Option func(options *Options)
  29. type Options struct {
  30. timeoutSec int64
  31. }
  32. func WithTimeoutSec(timeoutSec int64) Option {
  33. return func(options *Options) {
  34. options.timeoutSec = timeoutSec
  35. }
  36. }