Apply comments and naming conventions to HTTP proxy

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis 2018-03-03 10:49:16 +00:00
parent 26e0de3497
commit 7120e4c5f4
3 changed files with 10 additions and 5 deletions

View File

@ -14,7 +14,7 @@ import (
) )
// MakeForwardingProxyHandler create a handler which forwards HTTP requests // MakeForwardingProxyHandler create a handler which forwards HTTP requests
func MakeForwardingProxyHandler(proxy *types.HttpClientReverseProxy, metrics *metrics.MetricOptions) http.HandlerFunc { func MakeForwardingProxyHandler(proxy *types.HTTPClientReverseProxy, metrics *metrics.MetricOptions) http.HandlerFunc {
baseURL := proxy.BaseURL.String() baseURL := proxy.BaseURL.String()
if strings.HasSuffix(baseURL, "/") { if strings.HasSuffix(baseURL, "/") {
baseURL = baseURL[0 : len(baseURL)-1] baseURL = baseURL[0 : len(baseURL)-1]

View File

@ -40,7 +40,7 @@ func main() {
servicePollInterval := time.Second * 5 servicePollInterval := time.Second * 5
reverseProxy := types.NewHttpClientReverseProxy(config.FunctionsProviderURL, config.ReadTimeout) reverseProxy := types.NewHTTPClientReverseProxy(config.FunctionsProviderURL, config.ReadTimeout)
faasHandlers.Proxy = internalHandlers.MakeForwardingProxyHandler(reverseProxy, &metricsOptions) faasHandlers.Proxy = internalHandlers.MakeForwardingProxyHandler(reverseProxy, &metricsOptions)
faasHandlers.RoutelessProxy = internalHandlers.MakeForwardingProxyHandler(reverseProxy, &metricsOptions) faasHandlers.RoutelessProxy = internalHandlers.MakeForwardingProxyHandler(reverseProxy, &metricsOptions)

View File

@ -1,3 +1,6 @@
// Copyright (c) OpenFaaS Project 2018. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package types package types
import ( import (
@ -7,8 +10,9 @@ import (
"time" "time"
) )
func NewHttpClientReverseProxy(baseURL *url.URL, timeout time.Duration) *HttpClientReverseProxy { // NewHTTPClientReverseProxy proxies to an upstream host through the use of a http.Client
h := HttpClientReverseProxy{ func NewHTTPClientReverseProxy(baseURL *url.URL, timeout time.Duration) *HTTPClientReverseProxy {
h := HTTPClientReverseProxy{
BaseURL: baseURL, BaseURL: baseURL,
} }
@ -26,7 +30,8 @@ func NewHttpClientReverseProxy(baseURL *url.URL, timeout time.Duration) *HttpCli
return &h return &h
} }
type HttpClientReverseProxy struct { // HTTPClientReverseProxy proxy to a remote BaseURL using a http.Client
type HTTPClientReverseProxy struct {
BaseURL *url.URL BaseURL *url.URL
Client *http.Client Client *http.Client
} }