mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
chore(code): clean up the code EE-7251 (#11948)
Some checks are pending
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
This commit is contained in:
parent
be9d3285e1
commit
bfa27d9103
49 changed files with 338 additions and 368 deletions
|
@ -5,7 +5,7 @@ package request
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
|
@ -33,10 +33,11 @@ func RetrieveMultiPartFormFile(request *http.Request, requestParameter string) (
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
fileContent, err := ioutil.ReadAll(file)
|
||||
fileContent, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return fileContent, headers.Filename, nil
|
||||
}
|
||||
|
||||
|
@ -46,10 +47,10 @@ func RetrieveMultiPartFormJSONValue(request *http.Request, name string, target i
|
|||
value, err := RetrieveMultiPartFormValue(request, name, optional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if value == "" {
|
||||
} else if value == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(value), target)
|
||||
}
|
||||
|
||||
|
@ -60,6 +61,7 @@ func RetrieveMultiPartFormValue(request *http.Request, name string, optional boo
|
|||
if value == "" && !optional {
|
||||
return "", errors.New(ErrMissingFormDataValue)
|
||||
}
|
||||
|
||||
return value, nil
|
||||
}
|
||||
|
||||
|
@ -70,6 +72,7 @@ func RetrieveNumericMultiPartFormValue(request *http.Request, name string, optio
|
|||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.Atoi(value)
|
||||
}
|
||||
|
||||
|
@ -80,6 +83,7 @@ func RetrieveBooleanMultiPartFormValue(request *http.Request, name string, optio
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return value == "true", nil
|
||||
}
|
||||
|
||||
|
@ -89,10 +93,12 @@ func RetrieveRouteVariableValue(request *http.Request, name string) (string, err
|
|||
if routeVariables == nil {
|
||||
return "", errors.New(ErrInvalidRequestURL)
|
||||
}
|
||||
|
||||
routeVar := routeVariables[name]
|
||||
if routeVar == "" {
|
||||
return "", errors.New(ErrInvalidRequestURL)
|
||||
}
|
||||
|
||||
return routeVar, nil
|
||||
}
|
||||
|
||||
|
@ -102,6 +108,7 @@ func RetrieveNumericRouteVariableValue(request *http.Request, name string) (int,
|
|||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.Atoi(routeVar)
|
||||
}
|
||||
|
||||
|
@ -112,6 +119,7 @@ func RetrieveQueryParameter(request *http.Request, name string, optional bool) (
|
|||
if queryParameter == "" && !optional {
|
||||
return "", errors.New(ErrMissingQueryParameter)
|
||||
}
|
||||
|
||||
return queryParameter, nil
|
||||
}
|
||||
|
||||
|
@ -121,10 +129,10 @@ func RetrieveNumericQueryParameter(request *http.Request, name string, optional
|
|||
queryParameter, err := RetrieveQueryParameter(request, name, optional)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if queryParameter == "" && optional {
|
||||
} else if queryParameter == "" && optional {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
return strconv.Atoi(queryParameter)
|
||||
}
|
||||
|
||||
|
@ -135,6 +143,7 @@ func RetrieveBooleanQueryParameter(request *http.Request, name string, optional
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return queryParameter == "true", nil
|
||||
}
|
||||
|
||||
|
@ -144,9 +153,9 @@ func RetrieveJSONQueryParameter(request *http.Request, name string, target inter
|
|||
queryParameter, err := RetrieveQueryParameter(request, name, optional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if queryParameter == "" {
|
||||
} else if queryParameter == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(queryParameter), target)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue