Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin <kevin.kengne1@gmail.com>2020-12-28 22:52:21 +0300
committerKevin <kevin.kengne1@gmail.com>2021-01-11 12:21:57 +0300
commit372394c525abe23d653ab63027f33cda16578ef5 (patch)
tree484aca9eae3b4bafcaf2c16f4b7ef1f878f9329d /main.go
parentad8f7ff5423cde7b5f56d12b8fe592eb9b8193e0 (diff)
Refactor 'Error's not used as errors to strings
Change variables of error type to strings constants when these variables are solely used for the message contained in the errors.
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 15 insertions, 17 deletions
diff --git a/main.go b/main.go
index 802b98fd..f54bfcd7 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,6 @@ package main
import (
"encoding/base64"
- "errors"
"fmt"
"io"
"math/rand"
@@ -95,15 +94,14 @@ var (
header MultiStringFlag
)
-var (
- errArtifactSchemaUnsupported = errors.New("artifacts-server scheme must be either http:// or https://")
- errArtifactsServerTimeoutValue = errors.New("artifacts-server-timeout must be greater than or equal to 1")
-
- errSecretNotDefined = errors.New("auth-secret must be defined if authentication is supported")
- errClientIDNotDefined = errors.New("auth-client-id must be defined if authentication is supported")
- errClientSecretNotDefined = errors.New("auth-client-secret must be defined if authentication is supported")
- errGitLabServerNotDefined = errors.New("gitlab-server must be defined if authentication is supported")
- errRedirectURINotDefined = errors.New("auth-redirect-uri must be defined if authentication is supported")
+const (
+ artifactSchemaUnsupportedErrMsg = "artifacts-server scheme must be either http:// or https://"
+ artifactsServerTimeoutValueErrMsg = "artifacts-server-timeout must be greater than or equal to 1"
+ clientIDNotDefinedErrMsg = "auth-client-id must be defined if authentication is supported"
+ clientSecretNotDefinedErrMsg = "auth-client-secret must be defined if authentication is supported" // #nosec
+ gitLabServerNotDefinedErrMsg = "gitlab-server must be defined if authentication is supported"
+ redirectURINotDefinedErrMsg = "auth-redirect-uri must be defined if authentication is supported"
+ secretNotDefinedErrMsg = "auth-secret must be defined if authentication is supported"
)
func gitlabServerFromFlags() string {
@@ -141,12 +139,12 @@ func setArtifactsServer(artifactsServer string, artifactsServerTimeout int, conf
// url.Parse ensures that the Scheme attribute is always lower case.
if u.Scheme != request.SchemeHTTP && u.Scheme != request.SchemeHTTPS {
errortracking.Capture(err)
- log.Fatal(errArtifactSchemaUnsupported)
+ log.Fatal(artifactSchemaUnsupportedErrMsg)
}
if artifactsServerTimeout < 1 {
errortracking.Capture(err)
- log.Fatal(errArtifactsServerTimeoutValue)
+ log.Fatal(artifactsServerTimeoutValueErrMsg)
}
config.ArtifactsServerTimeout = artifactsServerTimeout
@@ -238,19 +236,19 @@ func checkAuthenticationConfig(config appConfig) {
func assertAuthConfig(config appConfig) {
if config.StoreSecret == "" {
- log.Fatal(errSecretNotDefined)
+ log.Fatal(secretNotDefinedErrMsg)
}
if config.ClientID == "" {
- log.Fatal(errClientIDNotDefined)
+ log.Fatal(clientIDNotDefinedErrMsg)
}
if config.ClientSecret == "" {
- log.Fatal(errClientSecretNotDefined)
+ log.Fatal(clientSecretNotDefinedErrMsg)
}
if config.GitLabServer == "" {
- log.Fatal(errGitLabServerNotDefined)
+ log.Fatal(gitLabServerNotDefinedErrMsg)
}
if config.RedirectURI == "" {
- log.Fatal(errRedirectURINotDefined)
+ log.Fatal(redirectURINotDefinedErrMsg)
}
}