refactor: interfaces (#5252)

Use any alias instead of empty interfaces.

Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
pull/5255/head
James Elliott 2023-04-15 22:35:44 +10:00 committed by GitHub
parent 9e8db3c3f3
commit 4db965e19f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 27 deletions

View File

@ -260,7 +260,7 @@ func StringToAddressHookFunc() mapstructure.DecodeHookFuncType {
// StringToX509CertificateHookFunc decodes strings to x509.Certificate's.
func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data any) (value interface{}, err error) {
return func(f reflect.Type, t reflect.Type, data any) (value any, err error) {
if f.Kind() != reflect.String {
return data, nil
}
@ -283,7 +283,7 @@ func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType {
return result, nil
}
var i interface{}
var i any
if i, err = utils.ParseX509FromPEM([]byte(dataStr)); err != nil {
return nil, fmt.Errorf(errFmtDecodeHookCouldNotParseBasic, "*", expectedType, err)
@ -300,7 +300,7 @@ func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType {
// StringToX509CertificateChainHookFunc decodes strings to schema.X509CertificateChain's.
func StringToX509CertificateChainHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) {
return func(f reflect.Type, t reflect.Type, data any) (value any, err error) {
var ptr bool
if f.Kind() != reflect.String {
@ -348,7 +348,7 @@ func StringToX509CertificateChainHookFunc() mapstructure.DecodeHookFuncType {
// StringToTLSVersionHookFunc decodes strings to schema.TLSVersion's.
func StringToTLSVersionHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) {
return func(f reflect.Type, t reflect.Type, data any) (value any, err error) {
var ptr bool
if f.Kind() != reflect.String {
@ -388,7 +388,7 @@ func StringToTLSVersionHookFunc() mapstructure.DecodeHookFuncType {
// StringToCryptoPrivateKeyHookFunc decodes strings to schema.CryptographicPrivateKey's.
func StringToCryptoPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) {
return func(f reflect.Type, t reflect.Type, data any) (value any, err error) {
if f.Kind() != reflect.String {
return data, nil
}
@ -418,7 +418,7 @@ func StringToCryptoPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
// StringToPrivateKeyHookFunc decodes strings to rsa.PrivateKey's.
func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) {
return func(f reflect.Type, t reflect.Type, data any) (value any, err error) {
if f.Kind() != reflect.String {
return data, nil
}
@ -487,7 +487,7 @@ func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
// StringToPasswordDigestHookFunc decodes a string into a crypt.Digest.
func StringToPasswordDigestHookFunc() mapstructure.DecodeHookFuncType {
return func(f reflect.Type, t reflect.Type, data interface{}) (value interface{}, err error) {
return func(f reflect.Type, t reflect.Type, data any) (value any, err error) {
var ptr bool
if f.Kind() != reflect.String {

View File

@ -50,7 +50,7 @@ func (f *FilteredFile) ReadBytes() (data []byte, err error) {
}
// Read is not supported by the filtered file koanf.Provider.
func (f *FilteredFile) Read() (map[string]interface{}, error) {
func (f *FilteredFile) Read() (map[string]any, error) {
return nil, errors.New("filtered file provider does not support this method")
}

View File

@ -53,15 +53,15 @@ func koanfRemapKeys(val *schema.StructValidator, ko *koanf.Koanf, ds map[string]
return final, nil
}
func koanfRemapKeysStandard(keys map[string]any, val *schema.StructValidator, ds map[string]Deprecation) (keysFinal map[string]interface{}) {
func koanfRemapKeysStandard(keys map[string]any, val *schema.StructValidator, ds map[string]Deprecation) (keysFinal map[string]any) {
var (
ok bool
d Deprecation
key string
value interface{}
value any
)
keysFinal = make(map[string]interface{})
keysFinal = make(map[string]any)
for key, value = range keys {
if d, ok = ds[key]; ok {
@ -93,35 +93,35 @@ func koanfRemapKeysStandard(keys map[string]any, val *schema.StructValidator, ds
return keysFinal
}
func koanfRemapKeysMapped(keys map[string]interface{}, val *schema.StructValidator, ds map[string]Deprecation) (keysFinal map[string]interface{}) {
func koanfRemapKeysMapped(keys map[string]any, val *schema.StructValidator, ds map[string]Deprecation) (keysFinal map[string]any) {
var (
key string
value interface{}
slc, slcFinal []interface{}
value any
slc, slcFinal []any
ok bool
m map[string]interface{}
m map[string]any
d Deprecation
)
keysFinal = make(map[string]interface{})
keysFinal = make(map[string]any)
for key, value = range keys {
if slc, ok = value.([]interface{}); !ok {
if slc, ok = value.([]any); !ok {
keysFinal[key] = value
continue
}
slcFinal = make([]interface{}, len(slc))
slcFinal = make([]any, len(slc))
for i, item := range slc {
if m, ok = item.(map[string]interface{}); !ok {
if m, ok = item.(map[string]any); !ok {
slcFinal[i] = item
continue
}
itemFinal := make(map[string]interface{})
itemFinal := make(map[string]any)
for subkey, element := range m {
prefix := fmt.Sprintf("%s[].", key)

View File

@ -13,7 +13,7 @@ type PrintfLogger struct {
}
// Printf is the implementation of the interface.
func (l *PrintfLogger) Printf(format string, args ...interface{}) {
func (l *PrintfLogger) Printf(format string, args ...any) {
l.logrus.Logf(l.level, format, args...)
}
@ -24,6 +24,6 @@ type CtxPrintfLogger struct {
}
// Printf is the implementation of the interface.
func (l *CtxPrintfLogger) Printf(_ context.Context, format string, args ...interface{}) {
func (l *CtxPrintfLogger) Printf(_ context.Context, format string, args ...any) {
l.logrus.Logf(l.level, format, args...)
}

View File

@ -9,7 +9,7 @@ import (
)
func TestShouldEncryptAndDecrypt(t *testing.T) {
payload := session.Dict{KV: map[string]interface{}{"key": "value"}}
payload := session.Dict{KV: map[string]any{"key": "value"}}
dst, err := payload.MarshalMsg(nil)
require.NoError(t, err)
@ -28,7 +28,7 @@ func TestShouldEncryptAndDecrypt(t *testing.T) {
}
func TestShouldNotSupportUnencryptedSessionForBackwardCompatibility(t *testing.T) {
payload := session.Dict{KV: map[string]interface{}{"key": "value"}}
payload := session.Dict{KV: map[string]any{"key": "value"}}
dst, err := payload.MarshalMsg(nil)
require.NoError(t, err)

View File

@ -325,7 +325,7 @@ func TestShouldParseCurves(t *testing.T) {
}
}
func testMustBuildPrivateKey(b PrivateKeyBuilder) interface{} {
func testMustBuildPrivateKey(b PrivateKeyBuilder) any {
k, err := b.Build()
if err != nil {
panic(err)
@ -337,8 +337,8 @@ func testMustBuildPrivateKey(b PrivateKeyBuilder) interface{} {
func TestPublicKeyFromPrivateKey(t *testing.T) {
testCases := []struct {
Name string
PrivateKey interface{}
Expected interface{}
PrivateKey any
Expected any
}{
{
Name: "RSA2048",