From f8bbfba14609fc4df31a4beb2ca5ccc91cd8b79d Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Mon, 23 May 2022 14:09:57 +0900 Subject: [PATCH] cmd/fastly-exporter: move roundTripperFunc, userAgentTransport into main.go, allowing "go run cmd/fastly-exporter/main.go" --- cmd/fastly-exporter/main.go | 11 +++++++++++ .../{transport_test.go => main_test.go} | 0 cmd/fastly-exporter/transport.go | 14 -------------- 3 files changed, 11 insertions(+), 14 deletions(-) rename cmd/fastly-exporter/{transport_test.go => main_test.go} (100%) delete mode 100644 cmd/fastly-exporter/transport.go diff --git a/cmd/fastly-exporter/main.go b/cmd/fastly-exporter/main.go index b6b2a2d..6e9469e 100644 --- a/cmd/fastly-exporter/main.go +++ b/cmd/fastly-exporter/main.go @@ -473,3 +473,14 @@ func getLogLevel(debug bool) level.Option { return level.AllowInfo() } } + +type roundTripperFunc func(*http.Request) (*http.Response, error) + +func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req) } + +func userAgentTransport(next http.RoundTripper, userAgent string) http.RoundTripper { + return roundTripperFunc(func(req *http.Request) (*http.Response, error) { + req.Header.Set("User-Agent", userAgent) + return next.RoundTrip(req) + }) +} diff --git a/cmd/fastly-exporter/transport_test.go b/cmd/fastly-exporter/main_test.go similarity index 100% rename from cmd/fastly-exporter/transport_test.go rename to cmd/fastly-exporter/main_test.go diff --git a/cmd/fastly-exporter/transport.go b/cmd/fastly-exporter/transport.go deleted file mode 100644 index d456495..0000000 --- a/cmd/fastly-exporter/transport.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import "net/http" - -type roundTripperFunc func(*http.Request) (*http.Response, error) - -func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req) } - -func userAgentTransport(next http.RoundTripper, userAgent string) http.RoundTripper { - return roundTripperFunc(func(req *http.Request) (*http.Response, error) { - req.Header.Set("User-Agent", userAgent) - return next.RoundTrip(req) - }) -}