Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- ireturn
- lll
- musttag
- modernize
- nestif
- nlreturn
- nonamedreturns
Expand Down
2 changes: 1 addition & 1 deletion cmdutils/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ package cmdutils
type CommandLineOptionsGroup struct {
ShortDescription string
LongDescription string
Options interface{}
Options any
}
2 changes: 1 addition & 1 deletion conv/convert_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func assertSingleValue(t *testing.T, inElem, elem reflect.Value, expectPointer b
}

// assertValues checks equivalent representation pointer vs values for single var, slices and maps
func assertValues(t *testing.T, in, out interface{}, expectPointer bool, idx int) {
func assertValues(t *testing.T, in, out any, expectPointer bool, idx int) {
vin := reflect.ValueOf(in)
vout := reflect.ValueOf(out)

Expand Down
4 changes: 2 additions & 2 deletions fileutils/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
)

func TestFileImplementsIOReader(t *testing.T) {
var file interface{} = &File{}
var file any = &File{}
expected := "that File implements io.Reader"
assert.Implements(t, new(io.Reader), file, expected)
}

func TestFileImplementsIOReadCloser(t *testing.T) {
var file interface{} = &File{}
var file any = &File{}
expected := "that File implements io.ReadCloser"
assert.Implements(t, new(io.ReadCloser), file, expected)
}
6 changes: 3 additions & 3 deletions jsonname/name_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func newNameIndex(tpe reflect.Type) nameIndex {
}

// GetJSONNames gets all the json property names for a type
func (n *NameProvider) GetJSONNames(subject interface{}) []string {
func (n *NameProvider) GetJSONNames(subject any) []string {
n.lock.Lock()
defer n.lock.Unlock()
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
Expand All @@ -96,7 +96,7 @@ func (n *NameProvider) GetJSONNames(subject interface{}) []string {
}

// GetJSONName gets the json name for a go property name
func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool) {
func (n *NameProvider) GetJSONName(subject any, name string) (string, bool) {
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
return n.GetJSONNameForType(tpe, name)
}
Expand All @@ -114,7 +114,7 @@ func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string
}

// GetGoName gets the go name for a json property name
func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool) {
func (n *NameProvider) GetGoName(subject any, name string) (string, bool) {
tpe := reflect.Indirect(reflect.ValueOf(subject)).Type()
return n.GetGoNameForType(tpe, name)
}
Expand Down
18 changes: 9 additions & 9 deletions jsonutils_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ type JSONMapItem = jsonutils.JSONMapItem
// WriteJSON writes json data.
//
// Deprecated: use [jsonutils.WriteJSON] instead.
func WriteJSON(data interface{}) ([]byte, error) { return jsonutils.WriteJSON(data) }
func WriteJSON(data any) ([]byte, error) { return jsonutils.WriteJSON(data) }

// ReadJSON reads json data.
//
// Deprecated: use [jsonutils.ReadJSON] instead.
func ReadJSON(data []byte, value interface{}) error { return jsonutils.ReadJSON(data, value) }
func ReadJSON(data []byte, value any) error { return jsonutils.ReadJSON(data, value) }

// DynamicJSONToStruct converts an untyped JSON structure into a target data type.
//
// Deprecated: use [jsonutils.FromDynamicJSON] instead.
func DynamicJSONToStruct(data interface{}, target interface{}) error {
func DynamicJSONToStruct(data any, target any) error {
return jsonutils.FromDynamicJSON(data, target)
}

Expand All @@ -46,8 +46,8 @@ func ConcatJSON(blobs ...[]byte) []byte { return jsonutils.ConcatJSON(blobs...)
// It is the same as [FromDynamicJSON], but doesn't check for errors.
//
// Deprecated: this function is a misnomer and is unsafe. Use [jsonutils.FromDynamicJSON] instead.
func ToDynamicJSON(value interface{}) interface{} {
var res interface{}
func ToDynamicJSON(value any) any {
var res any
if err := FromDynamicJSON(value, &res); err != nil {
log.Println(err)
}
Expand All @@ -57,9 +57,9 @@ func ToDynamicJSON(value interface{}) interface{} {

// FromDynamicJSON turns a go value into a properly JSON typed structure.
//
// "Dynamic JSON" refers to what you get when unmarshaling JSON into an untyped interface{},
// i.e. objects are represented by map[string]interface{}, arrays by []interface{}, and all
// scalar values are interface{}.
// "Dynamic JSON" refers to what you get when unmarshaling JSON into an untyped any,
// i.e. objects are represented by map[string]any, arrays by []any, and all
// scalar values are any.
//
// Deprecated: use [jsonutils.FromDynamicJSON] instead.
func FromDynamicJSON(data, target interface{}) error { return jsonutils.FromDynamicJSON(data, target) }
func FromDynamicJSON(data, target any) error { return jsonutils.FromDynamicJSON(data, target) }
2 changes: 1 addition & 1 deletion loading/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func YAMLDoc(path string, opts ...Option) (json.RawMessage, error) {
}

// YAMLData loads a yaml document from either http or a file.
func YAMLData(path string, opts ...Option) (interface{}, error) {
func YAMLData(path string, opts ...Option) (any, error) {
data, err := LoadFromFileOrHTTP(path, opts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion loading_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func YAMLDoc(path string) (json.RawMessage, error) {
// YAMLData loads a yaml document from either http or a file.
//
// Deprecated: use [loading.YAMLData] instead.
func YAMLData(path string) (interface{}, error) {
func YAMLData(path string) (any, error) {
return loading.YAMLData(path)
}

Expand Down
10 changes: 2 additions & 8 deletions loading_iface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"net/http"
"net/http/httptest"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -62,14 +63,7 @@ func TestLoadFromHTTP(t *testing.T) {

ts := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
myHeaders := r.Header[sharedHeaderKey]
ok := false
for _, v := range myHeaders {
if v == sharedHeaderValue {
ok = true
break
}
}
if ok {
if slices.Contains(myHeaders, sharedHeaderValue) {
rw.WriteHeader(http.StatusOK)
} else {
rw.WriteHeader(http.StatusForbidden)
Expand Down
2 changes: 1 addition & 1 deletion typeutils_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import "github.com/go-openapi/swag/typeutils"
// This allows for safer checking of interface values.
//
// Deprecated: use [typeutils.IsZero] instead.
func IsZero(data interface{}) bool { return typeutils.IsZero(data) }
func IsZero(data any) bool { return typeutils.IsZero(data) }
4 changes: 2 additions & 2 deletions yamlutils_iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
// YAMLToJSON converts YAML unmarshaled data into json compatible data
//
// Deprecated: use [yamlutils.YAMLToJSON] instead.
func YAMLToJSON(data interface{}) (json.RawMessage, error) { return yamlutils.YAMLToJSON(data) }
func YAMLToJSON(data any) (json.RawMessage, error) { return yamlutils.YAMLToJSON(data) }

// BytesToYAMLDoc converts a byte slice into a YAML document
//
// Deprecated: use [yamlutils.BytesToYAMLDoc] instead.
func BytesToYAMLDoc(data []byte) (interface{}, error) { return yamlutils.BytesToYAMLDoc(data) }
func BytesToYAMLDoc(data []byte) (any, error) { return yamlutils.BytesToYAMLDoc(data) }
Loading