Adjust error messages to conform to Go best practices (#1400)
https://github.com/golang/go/wiki/CodeReviewComments#error-strings
This commit is contained in:
parent
3390385508
commit
4a04ecddd7
@ -22,18 +22,18 @@ func Restore(backupFile string, databaseFile string) error {
|
|||||||
|
|
||||||
data, err := ioutil.ReadFile(backupFile) // nolint
|
data, err := ioutil.ReadFile(backupFile) // nolint
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to read backup file %s", err)
|
return fmt.Errorf("unable to read backup file %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to read backup file %s", err)
|
return fmt.Errorf("unable to read backup file %s", err)
|
||||||
}
|
}
|
||||||
defer gz.Close()
|
defer gz.Close()
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if _, err := io.Copy(&b, gz); err != nil { // nolint
|
if _, err := io.Copy(&b, gz); err != nil { // nolint
|
||||||
return fmt.Errorf("Unable to read backup file %s", err)
|
return fmt.Errorf("unable to read backup file %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer gz.Close()
|
defer gz.Close()
|
||||||
@ -41,7 +41,7 @@ func Restore(backupFile string, databaseFile string) error {
|
|||||||
rawSQL := b.String()
|
rawSQL := b.String()
|
||||||
|
|
||||||
if _, err := os.Create(databaseFile); err != nil {
|
if _, err := os.Create(databaseFile); err != nil {
|
||||||
return errors.New("Unable to write restored database")
|
return errors.New("unable to write restored database")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new database by executing the raw SQL
|
// Create a new database by executing the raw SQL
|
||||||
|
@ -34,7 +34,7 @@ func mapPatternWithRequestURL(pattern string, requestURL string) (map[string]str
|
|||||||
if len(patternSplit) == len(requestURLSplit) {
|
if len(patternSplit) == len(requestURLSplit) {
|
||||||
return zip2D(&patternSplit, &requestURLSplit), nil
|
return zip2D(&patternSplit, &requestURLSplit), nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("The length of pattern and request Url does not match")
|
return nil, errors.New("the length of pattern and request Url does not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
func readParameter(pattern string, requestURL string, paramName string) (string, error) {
|
func readParameter(pattern string, requestURL string, paramName string) (string, error) {
|
||||||
@ -46,14 +46,14 @@ func readParameter(pattern string, requestURL string, paramName string) (string,
|
|||||||
if value, exists := all[fmt.Sprintf("{%s}", paramName)]; exists {
|
if value, exists := all[fmt.Sprintf("{%s}", paramName)]; exists {
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("Parameter with name %s not found", paramName)
|
return "", fmt.Errorf("parameter with name %s not found", paramName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadRestURLParameter will return the parameter from the request of the requested name.
|
// ReadRestURLParameter will return the parameter from the request of the requested name.
|
||||||
func ReadRestURLParameter(r *http.Request, parameterName string) (string, error) {
|
func ReadRestURLParameter(r *http.Request, parameterName string) (string, error) {
|
||||||
pattern, found := r.Header[restURLPatternHeaderKey]
|
pattern, found := r.Header[restURLPatternHeaderKey]
|
||||||
if !found {
|
if !found {
|
||||||
return "", fmt.Errorf("This HandlerFunc is not marked as REST-Endpoint. Cannot read Parameter '%s' from Request", parameterName)
|
return "", fmt.Errorf("this HandlerFunc is not marked as REST-Endpoint. Cannot read Parameter '%s' from Request", parameterName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return readParameter(pattern[0], r.URL.Path, parameterName)
|
return readParameter(pattern[0], r.URL.Path, parameterName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user