(logger *zap.SugaredLogger, proxyCfg *Config, enforcer casbin.Enforcer)
| 53 | } |
| 54 | |
| 55 | func NewProxyRouterImpl(logger *zap.SugaredLogger, proxyCfg *Config, enforcer casbin.Enforcer) (*ProxyRouterImpl, error) { |
| 56 | client := &http.Client{ |
| 57 | Transport: &http.Transport{ |
| 58 | Proxy: http.ProxyFromEnvironment, |
| 59 | Dial: (&net.Dialer{ |
| 60 | Timeout: 120 * time.Second, |
| 61 | KeepAlive: 120 * time.Second, |
| 62 | }).Dial, |
| 63 | TLSHandshakeTimeout: 10 * time.Second, |
| 64 | ExpectContinueTimeout: 1 * time.Second, |
| 65 | }, |
| 66 | } |
| 67 | proxyConnection := make(map[string]ProxyConnection) |
| 68 | err := json.Unmarshal([]byte(proxyCfg.ProxyServiceConfig), &proxyConnection) |
| 69 | if err != nil { |
| 70 | logger.Warnw("bad env value for PROXY_SERVICE_CONFIG", "err", err) |
| 71 | } |
| 72 | |
| 73 | proxy := make(map[string]func(writer http.ResponseWriter, request *http.Request)) |
| 74 | for s, connection := range proxyConnection { |
| 75 | proxy[s], err = NewHTTPReverseProxy(fmt.Sprintf("http://%s:%s", connection.Host, connection.Port), client.Transport, enforcer) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | router := &ProxyRouterImpl{ |
| 82 | proxy: proxy, |
| 83 | logger: logger, |
| 84 | } |
| 85 | return router, nil |
| 86 | } |
| 87 | |
| 88 | func (router ProxyRouterImpl) InitProxyRouter(ProxyRouter *mux.Router) { |
| 89 |
no test coverage detected
searching dependent graphs…