diff options
| author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-13 13:51:21 +0000 |
|---|---|---|
| committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2021-08-13 13:51:21 +0000 |
| commit | 160dcb064412e53a638c4329a60feadaafb1ab48 (patch) | |
| tree | df8c4dd3134cc1905043b8d62c4b1705dddd7bc6 /internal/config | |
| parent | 8a1d584de771b3267374397cc99c019de1c4500c (diff) | |
| download | gitlab-shell-160dcb064412e53a638c4329a60feadaafb1ab48.tar.gz | |
refactor: change httpclient to return an error
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 9 | ||||
| -rw-r--r-- | internal/config/config_test.go | 5 |
2 files changed, 8 insertions, 6 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 41ad7cd..f69a6c8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -15,7 +15,6 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/client" "gitlab.com/gitlab-org/gitlab-shell/internal/metrics" - "gitlab.com/gitlab-org/labkit/log" ) const ( @@ -59,6 +58,7 @@ type Config struct { Server ServerConfig `yaml:"sshd"` httpClient *client.HttpClient + httpClientErr error httpClientOnce sync.Once } @@ -96,7 +96,7 @@ func (c *Config) ApplyGlobalState() { } } -func (c *Config) HttpClient() *client.HttpClient { +func (c *Config) HttpClient() (*client.HttpClient, error) { c.httpClientOnce.Do(func() { client, err := client.NewHTTPClientWithOpts( c.GitlabUrl, @@ -108,7 +108,8 @@ func (c *Config) HttpClient() *client.HttpClient { nil, ) if err != nil { - log.WithError(err).Fatal("new http client with opts") + c.httpClientErr = err + return } tr := client.Transport @@ -117,7 +118,7 @@ func (c *Config) HttpClient() *client.HttpClient { c.httpClient = client }) - return c.httpClient + return c.httpClient, c.httpClientErr } // NewFromDirExternal returns a new config from a given root dir. It also applies defaults appropriate for diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 5fa8e66..699a261 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -29,9 +29,10 @@ func TestHttpClient(t *testing.T) { url := testserver.StartHttpServer(t, []testserver.TestRequestHandler{}) config := &Config{GitlabUrl: url} - client := config.HttpClient() + client, err := config.HttpClient() + require.NoError(t, err) - _, err := client.Get("http://host.com/path") + _, err = client.Get("http://host.com/path") require.NoError(t, err) ms, err := prometheus.DefaultGatherer.Gather() |
