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
parent
9e8db3c3f3
commit
4db965e19f
|
@ -260,7 +260,7 @@ func StringToAddressHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
|
|
||||||
// StringToX509CertificateHookFunc decodes strings to x509.Certificate's.
|
// StringToX509CertificateHookFunc decodes strings to x509.Certificate's.
|
||||||
func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType {
|
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 {
|
if f.Kind() != reflect.String {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var i interface{}
|
var i any
|
||||||
|
|
||||||
if i, err = utils.ParseX509FromPEM([]byte(dataStr)); err != nil {
|
if i, err = utils.ParseX509FromPEM([]byte(dataStr)); err != nil {
|
||||||
return nil, fmt.Errorf(errFmtDecodeHookCouldNotParseBasic, "*", expectedType, err)
|
return nil, fmt.Errorf(errFmtDecodeHookCouldNotParseBasic, "*", expectedType, err)
|
||||||
|
@ -300,7 +300,7 @@ func StringToX509CertificateHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
|
|
||||||
// StringToX509CertificateChainHookFunc decodes strings to schema.X509CertificateChain's.
|
// StringToX509CertificateChainHookFunc decodes strings to schema.X509CertificateChain's.
|
||||||
func StringToX509CertificateChainHookFunc() mapstructure.DecodeHookFuncType {
|
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
|
var ptr bool
|
||||||
|
|
||||||
if f.Kind() != reflect.String {
|
if f.Kind() != reflect.String {
|
||||||
|
@ -348,7 +348,7 @@ func StringToX509CertificateChainHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
|
|
||||||
// StringToTLSVersionHookFunc decodes strings to schema.TLSVersion's.
|
// StringToTLSVersionHookFunc decodes strings to schema.TLSVersion's.
|
||||||
func StringToTLSVersionHookFunc() mapstructure.DecodeHookFuncType {
|
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
|
var ptr bool
|
||||||
|
|
||||||
if f.Kind() != reflect.String {
|
if f.Kind() != reflect.String {
|
||||||
|
@ -388,7 +388,7 @@ func StringToTLSVersionHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
|
|
||||||
// StringToCryptoPrivateKeyHookFunc decodes strings to schema.CryptographicPrivateKey's.
|
// StringToCryptoPrivateKeyHookFunc decodes strings to schema.CryptographicPrivateKey's.
|
||||||
func StringToCryptoPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
|
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 {
|
if f.Kind() != reflect.String {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ func StringToCryptoPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
|
|
||||||
// StringToPrivateKeyHookFunc decodes strings to rsa.PrivateKey's.
|
// StringToPrivateKeyHookFunc decodes strings to rsa.PrivateKey's.
|
||||||
func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
|
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 {
|
if f.Kind() != reflect.String {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
@ -487,7 +487,7 @@ func StringToPrivateKeyHookFunc() mapstructure.DecodeHookFuncType {
|
||||||
|
|
||||||
// StringToPasswordDigestHookFunc decodes a string into a crypt.Digest.
|
// StringToPasswordDigestHookFunc decodes a string into a crypt.Digest.
|
||||||
func StringToPasswordDigestHookFunc() mapstructure.DecodeHookFuncType {
|
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
|
var ptr bool
|
||||||
|
|
||||||
if f.Kind() != reflect.String {
|
if f.Kind() != reflect.String {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (f *FilteredFile) ReadBytes() (data []byte, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read is not supported by the filtered file koanf.Provider.
|
// 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")
|
return nil, errors.New("filtered file provider does not support this method")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,15 +53,15 @@ func koanfRemapKeys(val *schema.StructValidator, ko *koanf.Koanf, ds map[string]
|
||||||
return final, nil
|
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 (
|
var (
|
||||||
ok bool
|
ok bool
|
||||||
d Deprecation
|
d Deprecation
|
||||||
key string
|
key string
|
||||||
value interface{}
|
value any
|
||||||
)
|
)
|
||||||
|
|
||||||
keysFinal = make(map[string]interface{})
|
keysFinal = make(map[string]any)
|
||||||
|
|
||||||
for key, value = range keys {
|
for key, value = range keys {
|
||||||
if d, ok = ds[key]; ok {
|
if d, ok = ds[key]; ok {
|
||||||
|
@ -93,35 +93,35 @@ func koanfRemapKeysStandard(keys map[string]any, val *schema.StructValidator, ds
|
||||||
return keysFinal
|
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 (
|
var (
|
||||||
key string
|
key string
|
||||||
value interface{}
|
value any
|
||||||
slc, slcFinal []interface{}
|
slc, slcFinal []any
|
||||||
ok bool
|
ok bool
|
||||||
m map[string]interface{}
|
m map[string]any
|
||||||
d Deprecation
|
d Deprecation
|
||||||
)
|
)
|
||||||
|
|
||||||
keysFinal = make(map[string]interface{})
|
keysFinal = make(map[string]any)
|
||||||
|
|
||||||
for key, value = range keys {
|
for key, value = range keys {
|
||||||
if slc, ok = value.([]interface{}); !ok {
|
if slc, ok = value.([]any); !ok {
|
||||||
keysFinal[key] = value
|
keysFinal[key] = value
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
slcFinal = make([]interface{}, len(slc))
|
slcFinal = make([]any, len(slc))
|
||||||
|
|
||||||
for i, item := range 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
|
slcFinal[i] = item
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
itemFinal := make(map[string]interface{})
|
itemFinal := make(map[string]any)
|
||||||
|
|
||||||
for subkey, element := range m {
|
for subkey, element := range m {
|
||||||
prefix := fmt.Sprintf("%s[].", key)
|
prefix := fmt.Sprintf("%s[].", key)
|
||||||
|
|
|
@ -13,7 +13,7 @@ type PrintfLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printf is the implementation of the interface.
|
// 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...)
|
l.logrus.Logf(l.level, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,6 @@ type CtxPrintfLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printf is the implementation of the interface.
|
// 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...)
|
l.logrus.Logf(l.level, format, args...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestShouldEncryptAndDecrypt(t *testing.T) {
|
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)
|
dst, err := payload.MarshalMsg(nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -28,7 +28,7 @@ func TestShouldEncryptAndDecrypt(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShouldNotSupportUnencryptedSessionForBackwardCompatibility(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)
|
dst, err := payload.MarshalMsg(nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
@ -325,7 +325,7 @@ func TestShouldParseCurves(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMustBuildPrivateKey(b PrivateKeyBuilder) interface{} {
|
func testMustBuildPrivateKey(b PrivateKeyBuilder) any {
|
||||||
k, err := b.Build()
|
k, err := b.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -337,8 +337,8 @@ func testMustBuildPrivateKey(b PrivateKeyBuilder) interface{} {
|
||||||
func TestPublicKeyFromPrivateKey(t *testing.T) {
|
func TestPublicKeyFromPrivateKey(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
Name string
|
Name string
|
||||||
PrivateKey interface{}
|
PrivateKey any
|
||||||
Expected interface{}
|
Expected any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "RSA2048",
|
Name: "RSA2048",
|
||||||
|
|
Loading…
Reference in New Issue