| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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, gw.options.httpClientTimeoutSec)
- }
- type Option func(options *Options)
- type Options struct {
- httpClientTimeoutSec int64
- }
- func WithHttpClientTimeoutSec(httpClientTimeoutSec int64) Option {
- return func(options *Options) {
- options.httpClientTimeoutSec = httpClientTimeoutSec
- }
- }
|