| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package gateway
- import (
- "git.sxidc.com/go-framework/baize/framework/core/api"
- "git.sxidc.com/go-tools/utils/http_client"
- )
- type Gateway struct {
- api *api.Api
- httpClient *http_client.Client
- options *Options
- }
- func NewGateway(api *api.Api, opts ...Option) *Gateway {
- options := new(Options)
- for _, opt := range opts {
- opt(options)
- }
- if options.httpClientTimeoutSec == 0 {
- options.httpClientTimeoutSec = 30
- }
- return &Gateway{
- api: api,
- httpClient: http_client.New(),
- options: options,
- }
- }
- func DestroyGateway(gw *Gateway) {
- if gw == nil {
- return
- }
- gw.api = nil
- gw = nil
- }
- func (gw *Gateway) NewBuilder(routerType string, version string) *Builder {
- return newBuilder(gw.api.ChooseRouter(routerType, version), gw.httpClient)
- }
- type Option func(options *Options)
- type Options struct {
- httpClientTimeoutSec int64
- }
- func WithHttpClientTimeoutSec(httpClientTimeoutSec int64) Option {
- return func(options *Options) {
- options.httpClientTimeoutSec = httpClientTimeoutSec
- }
- }
|