mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 12:25:22 +02:00
chore(code): replace interface{} with any EE-6513 (#11986)
This commit is contained in:
parent
9c4935286f
commit
f0d43f941f
66 changed files with 231 additions and 231 deletions
|
@ -13,25 +13,25 @@ import (
|
|||
|
||||
// GetJSONObject will extract an object from a specific property of another JSON object.
|
||||
// Returns nil if nothing is associated to the specified key.
|
||||
func GetJSONObject(jsonObject map[string]interface{}, property string) map[string]interface{} {
|
||||
func GetJSONObject(jsonObject map[string]any, property string) map[string]any {
|
||||
object := jsonObject[property]
|
||||
if object != nil {
|
||||
return object.(map[string]interface{})
|
||||
return object.(map[string]any)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetArrayObject will extract an array from a specific property of another JSON object.
|
||||
// Returns nil if nothing is associated to the specified key.
|
||||
func GetArrayObject(jsonObject map[string]interface{}, property string) []interface{} {
|
||||
func GetArrayObject(jsonObject map[string]any, property string) []any {
|
||||
object := jsonObject[property]
|
||||
if object != nil {
|
||||
return object.([]interface{})
|
||||
return object.([]any)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{}, error) {
|
||||
func getBody(body io.ReadCloser, contentType string, isGzip bool) (any, error) {
|
||||
if body == nil {
|
||||
return nil, errors.New("unable to parse response: empty response body")
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
|
|||
|
||||
defer reader.Close()
|
||||
|
||||
var data interface{}
|
||||
var data any
|
||||
err := unmarshal(contentType, reader, &data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -58,7 +58,7 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
|
|||
return data, nil
|
||||
}
|
||||
|
||||
func marshal(contentType string, data interface{}) ([]byte, error) {
|
||||
func marshal(contentType string, data any) ([]byte, error) {
|
||||
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
|
@ -75,7 +75,7 @@ func marshal(contentType string, data interface{}) ([]byte, error) {
|
|||
return nil, fmt.Errorf("content type is not supported for marshaling: %s", contentType)
|
||||
}
|
||||
|
||||
func unmarshal(contentType string, body io.Reader, returnBody interface{}) error {
|
||||
func unmarshal(contentType string, body io.Reader, returnBody any) error {
|
||||
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
|
|
|
@ -12,13 +12,13 @@ import (
|
|||
)
|
||||
|
||||
// GetResponseAsJSONObject returns the response content as a generic JSON object
|
||||
func GetResponseAsJSONObject(response *http.Response) (map[string]interface{}, error) {
|
||||
func GetResponseAsJSONObject(response *http.Response) (map[string]any, error) {
|
||||
responseData, err := getResponseBody(response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
responseObject, ok := responseData.(map[string]interface{})
|
||||
responseObject, ok := responseData.(map[string]any)
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func GetResponseAsJSONObject(response *http.Response) (map[string]interface{}, e
|
|||
}
|
||||
|
||||
// GetResponseAsJSONArray returns the response content as an array of generic JSON object
|
||||
func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
|
||||
func GetResponseAsJSONArray(response *http.Response) ([]any, error) {
|
||||
responseData, err := getResponseBody(response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -36,9 +36,9 @@ func GetResponseAsJSONArray(response *http.Response) ([]interface{}, error) {
|
|||
}
|
||||
|
||||
switch responseObject := responseData.(type) {
|
||||
case []interface{}:
|
||||
case []any:
|
||||
return responseObject, nil
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
if responseObject["message"] != nil {
|
||||
return nil, errors.New(responseObject["message"].(string))
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func RewriteAccessDeniedResponse(response *http.Response) error {
|
|||
|
||||
// RewriteResponse will replace the existing response body and status code with the one specified
|
||||
// in parameters
|
||||
func RewriteResponse(response *http.Response, newResponseData interface{}, statusCode int) error {
|
||||
func RewriteResponse(response *http.Response, newResponseData any, statusCode int) error {
|
||||
data, err := marshal(getContentType(response), newResponseData)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -96,7 +96,7 @@ func RewriteResponse(response *http.Response, newResponseData interface{}, statu
|
|||
return nil
|
||||
}
|
||||
|
||||
func getResponseBody(response *http.Response) (interface{}, error) {
|
||||
func getResponseBody(response *http.Response) (any, error) {
|
||||
isGzip := response.Header.Get("Content-Encoding") == "gzip"
|
||||
if isGzip {
|
||||
response.Header.Del("Content-Encoding")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue