[#68] Replace interface{} with any
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
15b4287092
commit
9a072a8f49
7 changed files with 50 additions and 50 deletions
|
@ -15,7 +15,7 @@ package apistatus
|
||||||
// It should be noted that using direct typecasting is not a compatible approach.
|
// It should be noted that using direct typecasting is not a compatible approach.
|
||||||
//
|
//
|
||||||
// To transport statuses using the FrostFS API V2 protocol, see StatusV2 interface and FromStatusV2 and ToStatusV2 functions.
|
// To transport statuses using the FrostFS API V2 protocol, see StatusV2 interface and FromStatusV2 and ToStatusV2 functions.
|
||||||
type Status interface{}
|
type Status any
|
||||||
|
|
||||||
// ErrFromStatus converts Status instance to error if it is failed. Returns nil on successful Status.
|
// ErrFromStatus converts Status instance to error if it is failed. Returns nil on successful Status.
|
||||||
//
|
//
|
||||||
|
|
|
@ -123,7 +123,7 @@ func ToStatusV2(st Status) *status.Status {
|
||||||
return internalErrorStatus
|
return internalErrorStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func errMessageStatusV2(code interface{}, msg string) string {
|
func errMessageStatusV2(code any, msg string) string {
|
||||||
const (
|
const (
|
||||||
noMsgFmt = "status: code = %v"
|
noMsgFmt = "status: code = %v"
|
||||||
msgFmt = noMsgFmt + " message = %s"
|
msgFmt = noMsgFmt + " message = %s"
|
||||||
|
|
|
@ -12,7 +12,7 @@ func TestToStatusV2(t *testing.T) {
|
||||||
type statusConstructor func() apistatus.Status
|
type statusConstructor func() apistatus.Status
|
||||||
|
|
||||||
for _, testItem := range [...]struct {
|
for _, testItem := range [...]struct {
|
||||||
status interface{} // Status or statusConstructor
|
status any // Status or statusConstructor
|
||||||
codeV2 uint64
|
codeV2 uint64
|
||||||
messageV2 string
|
messageV2 string
|
||||||
}{
|
}{
|
||||||
|
@ -165,7 +165,7 @@ func TestFromStatusV2(t *testing.T) {
|
||||||
type statusConstructor func() apistatus.Status
|
type statusConstructor func() apistatus.Status
|
||||||
|
|
||||||
for _, testItem := range [...]struct {
|
for _, testItem := range [...]struct {
|
||||||
status interface{} // Status or statusConstructor
|
status any // Status or statusConstructor
|
||||||
codeV2 uint64
|
codeV2 uint64
|
||||||
messageV2 string
|
messageV2 string
|
||||||
}{
|
}{
|
||||||
|
|
|
@ -61,16 +61,16 @@ func TestNetworkInfo_MsPerBlock(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigValue(t *testing.T,
|
func testConfigValue(t *testing.T,
|
||||||
getter func(x NetworkInfo) interface{},
|
getter func(x NetworkInfo) any,
|
||||||
setter func(x *NetworkInfo, val interface{}),
|
setter func(x *NetworkInfo, val any),
|
||||||
val1, val2 interface{},
|
val1, val2 any,
|
||||||
v2Key string, v2Val func(val interface{}) []byte,
|
v2Key string, v2Val func(val any) []byte,
|
||||||
) {
|
) {
|
||||||
var x NetworkInfo
|
var x NetworkInfo
|
||||||
|
|
||||||
require.Zero(t, getter(x))
|
require.Zero(t, getter(x))
|
||||||
|
|
||||||
checkVal := func(exp interface{}) {
|
checkVal := func(exp any) {
|
||||||
require.EqualValues(t, exp, getter(x))
|
require.EqualValues(t, exp, getter(x))
|
||||||
|
|
||||||
var m netmap.NetworkInfo
|
var m netmap.NetworkInfo
|
||||||
|
@ -97,10 +97,10 @@ func testConfigValue(t *testing.T,
|
||||||
|
|
||||||
func TestNetworkInfo_AuditFee(t *testing.T) {
|
func TestNetworkInfo_AuditFee(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.AuditFee() },
|
func(x NetworkInfo) any { return x.AuditFee() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetAuditFee(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetAuditFee(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"AuditFee", func(val interface{}) []byte {
|
"AuditFee", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -110,10 +110,10 @@ func TestNetworkInfo_AuditFee(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_StoragePrice(t *testing.T) {
|
func TestNetworkInfo_StoragePrice(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.StoragePrice() },
|
func(x NetworkInfo) any { return x.StoragePrice() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetStoragePrice(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetStoragePrice(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"BasicIncomeRate", func(val interface{}) []byte {
|
"BasicIncomeRate", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -123,10 +123,10 @@ func TestNetworkInfo_StoragePrice(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_ContainerFee(t *testing.T) {
|
func TestNetworkInfo_ContainerFee(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.ContainerFee() },
|
func(x NetworkInfo) any { return x.ContainerFee() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetContainerFee(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetContainerFee(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"ContainerFee", func(val interface{}) []byte {
|
"ContainerFee", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -136,10 +136,10 @@ func TestNetworkInfo_ContainerFee(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_NamedContainerFee(t *testing.T) {
|
func TestNetworkInfo_NamedContainerFee(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.NamedContainerFee() },
|
func(x NetworkInfo) any { return x.NamedContainerFee() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetNamedContainerFee(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetNamedContainerFee(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"ContainerAliasFee", func(val interface{}) []byte {
|
"ContainerAliasFee", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -149,10 +149,10 @@ func TestNetworkInfo_NamedContainerFee(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_IRCandidateFee(t *testing.T) {
|
func TestNetworkInfo_IRCandidateFee(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.IRCandidateFee() },
|
func(x NetworkInfo) any { return x.IRCandidateFee() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetIRCandidateFee(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetIRCandidateFee(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"InnerRingCandidateFee", func(val interface{}) []byte {
|
"InnerRingCandidateFee", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -162,10 +162,10 @@ func TestNetworkInfo_IRCandidateFee(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_MaxObjectSize(t *testing.T) {
|
func TestNetworkInfo_MaxObjectSize(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.MaxObjectSize() },
|
func(x NetworkInfo) any { return x.MaxObjectSize() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetMaxObjectSize(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetMaxObjectSize(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"MaxObjectSize", func(val interface{}) []byte {
|
"MaxObjectSize", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -175,10 +175,10 @@ func TestNetworkInfo_MaxObjectSize(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_WithdrawalFee(t *testing.T) {
|
func TestNetworkInfo_WithdrawalFee(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.WithdrawalFee() },
|
func(x NetworkInfo) any { return x.WithdrawalFee() },
|
||||||
func(info *NetworkInfo, val interface{}) { info.SetWithdrawalFee(val.(uint64)) },
|
func(info *NetworkInfo, val any) { info.SetWithdrawalFee(val.(uint64)) },
|
||||||
uint64(1), uint64(2),
|
uint64(1), uint64(2),
|
||||||
"WithdrawFee", func(val interface{}) []byte {
|
"WithdrawFee", func(val any) []byte {
|
||||||
data := make([]byte, 8)
|
data := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(data, val.(uint64))
|
binary.LittleEndian.PutUint64(data, val.(uint64))
|
||||||
return data
|
return data
|
||||||
|
@ -188,14 +188,14 @@ func TestNetworkInfo_WithdrawalFee(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) {
|
func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.HomomorphicHashingDisabled() },
|
func(x NetworkInfo) any { return x.HomomorphicHashingDisabled() },
|
||||||
func(info *NetworkInfo, val interface{}) {
|
func(info *NetworkInfo, val any) {
|
||||||
if val.(bool) {
|
if val.(bool) {
|
||||||
info.DisableHomomorphicHashing()
|
info.DisableHomomorphicHashing()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true, true, // it is impossible to enable hashing
|
true, true, // it is impossible to enable hashing
|
||||||
"HomomorphicHashingDisabled", func(val interface{}) []byte {
|
"HomomorphicHashingDisabled", func(val any) []byte {
|
||||||
data := make([]byte, 1)
|
data := make([]byte, 1)
|
||||||
|
|
||||||
if val.(bool) {
|
if val.(bool) {
|
||||||
|
@ -209,14 +209,14 @@ func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) {
|
||||||
|
|
||||||
func TestNetworkInfo_MaintenanceModeAllowed(t *testing.T) {
|
func TestNetworkInfo_MaintenanceModeAllowed(t *testing.T) {
|
||||||
testConfigValue(t,
|
testConfigValue(t,
|
||||||
func(x NetworkInfo) interface{} { return x.MaintenanceModeAllowed() },
|
func(x NetworkInfo) any { return x.MaintenanceModeAllowed() },
|
||||||
func(info *NetworkInfo, val interface{}) {
|
func(info *NetworkInfo, val any) {
|
||||||
if val.(bool) {
|
if val.(bool) {
|
||||||
info.AllowMaintenanceMode()
|
info.AllowMaintenanceMode()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true, true,
|
true, true,
|
||||||
"MaintenanceModeAllowed", func(val interface{}) []byte {
|
"MaintenanceModeAllowed", func(val any) []byte {
|
||||||
if val.(bool) {
|
if val.(bool) {
|
||||||
return []byte{1}
|
return []byte{1}
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,17 +541,17 @@ type policyVisitor struct {
|
||||||
antlr.DefaultErrorListener
|
antlr.DefaultErrorListener
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyVisitor) SyntaxError(_ antlr.Recognizer, _ interface{}, line, column int, msg string, _ antlr.RecognitionException) {
|
func (p *policyVisitor) SyntaxError(_ antlr.Recognizer, _ any, line, column int, msg string, _ antlr.RecognitionException) {
|
||||||
p.reportError(fmt.Errorf("%w: line %d:%d %s", errSyntaxError, line, column, msg))
|
p.reportError(fmt.Errorf("%w: line %d:%d %s", errSyntaxError, line, column, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyVisitor) reportError(err error) interface{} {
|
func (p *policyVisitor) reportError(err error) any {
|
||||||
p.errors = append(p.errors, err)
|
p.errors = append(p.errors, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitPolicy implements parser.QueryVisitor interface.
|
// VisitPolicy implements parser.QueryVisitor interface.
|
||||||
func (p *policyVisitor) VisitPolicy(ctx *parser.PolicyContext) interface{} {
|
func (p *policyVisitor) VisitPolicy(ctx *parser.PolicyContext) any {
|
||||||
if len(p.errors) != 0 {
|
if len(p.errors) != 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -599,7 +599,7 @@ func (p *policyVisitor) VisitPolicy(ctx *parser.PolicyContext) interface{} {
|
||||||
return pl
|
return pl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyVisitor) VisitCbfStmt(ctx *parser.CbfStmtContext) interface{} {
|
func (p *policyVisitor) VisitCbfStmt(ctx *parser.CbfStmtContext) any {
|
||||||
cbf, err := strconv.ParseUint(ctx.GetBackupFactor().GetText(), 10, 32)
|
cbf, err := strconv.ParseUint(ctx.GetBackupFactor().GetText(), 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p.reportError(errInvalidNumber)
|
return p.reportError(errInvalidNumber)
|
||||||
|
@ -609,7 +609,7 @@ func (p *policyVisitor) VisitCbfStmt(ctx *parser.CbfStmtContext) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitRepStmt implements parser.QueryVisitor interface.
|
// VisitRepStmt implements parser.QueryVisitor interface.
|
||||||
func (p *policyVisitor) VisitRepStmt(ctx *parser.RepStmtContext) interface{} {
|
func (p *policyVisitor) VisitRepStmt(ctx *parser.RepStmtContext) any {
|
||||||
num, err := strconv.ParseUint(ctx.GetCount().GetText(), 10, 32)
|
num, err := strconv.ParseUint(ctx.GetCount().GetText(), 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p.reportError(errInvalidNumber)
|
return p.reportError(errInvalidNumber)
|
||||||
|
@ -626,7 +626,7 @@ func (p *policyVisitor) VisitRepStmt(ctx *parser.RepStmtContext) interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitSelectStmt implements parser.QueryVisitor interface.
|
// VisitSelectStmt implements parser.QueryVisitor interface.
|
||||||
func (p *policyVisitor) VisitSelectStmt(ctx *parser.SelectStmtContext) interface{} {
|
func (p *policyVisitor) VisitSelectStmt(ctx *parser.SelectStmtContext) any {
|
||||||
res, err := strconv.ParseUint(ctx.GetCount().GetText(), 10, 32)
|
res, err := strconv.ParseUint(ctx.GetCount().GetText(), 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p.reportError(errInvalidNumber)
|
return p.reportError(errInvalidNumber)
|
||||||
|
@ -652,13 +652,13 @@ func (p *policyVisitor) VisitSelectStmt(ctx *parser.SelectStmtContext) interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitFilterStmt implements parser.QueryVisitor interface.
|
// VisitFilterStmt implements parser.QueryVisitor interface.
|
||||||
func (p *policyVisitor) VisitFilterStmt(ctx *parser.FilterStmtContext) interface{} {
|
func (p *policyVisitor) VisitFilterStmt(ctx *parser.FilterStmtContext) any {
|
||||||
f := p.VisitFilterExpr(ctx.GetExpr().(*parser.FilterExprContext)).(*netmap.Filter)
|
f := p.VisitFilterExpr(ctx.GetExpr().(*parser.FilterExprContext)).(*netmap.Filter)
|
||||||
f.SetName(ctx.GetName().GetText())
|
f.SetName(ctx.GetName().GetText())
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyVisitor) VisitFilterExpr(ctx *parser.FilterExprContext) interface{} {
|
func (p *policyVisitor) VisitFilterExpr(ctx *parser.FilterExprContext) any {
|
||||||
if eCtx := ctx.Expr(); eCtx != nil {
|
if eCtx := ctx.Expr(); eCtx != nil {
|
||||||
return eCtx.Accept(p)
|
return eCtx.Accept(p)
|
||||||
}
|
}
|
||||||
|
@ -687,7 +687,7 @@ func (p *policyVisitor) VisitFilterExpr(ctx *parser.FilterExprContext) interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitFilterKey implements parser.QueryVisitor interface.
|
// VisitFilterKey implements parser.QueryVisitor interface.
|
||||||
func (p *policyVisitor) VisitFilterKey(ctx *parser.FilterKeyContext) interface{} {
|
func (p *policyVisitor) VisitFilterKey(ctx *parser.FilterKeyContext) any {
|
||||||
if id := ctx.Ident(); id != nil {
|
if id := ctx.Ident(); id != nil {
|
||||||
return id.GetText()
|
return id.GetText()
|
||||||
}
|
}
|
||||||
|
@ -696,7 +696,7 @@ func (p *policyVisitor) VisitFilterKey(ctx *parser.FilterKeyContext) interface{}
|
||||||
return str[1 : len(str)-1]
|
return str[1 : len(str)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *policyVisitor) VisitFilterValue(ctx *parser.FilterValueContext) interface{} {
|
func (p *policyVisitor) VisitFilterValue(ctx *parser.FilterValueContext) any {
|
||||||
if id := ctx.Ident(); id != nil {
|
if id := ctx.Ident(); id != nil {
|
||||||
return id.GetText()
|
return id.GetText()
|
||||||
}
|
}
|
||||||
|
@ -710,7 +710,7 @@ func (p *policyVisitor) VisitFilterValue(ctx *parser.FilterValueContext) interfa
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitExpr implements parser.QueryVisitor interface.
|
// VisitExpr implements parser.QueryVisitor interface.
|
||||||
func (p *policyVisitor) VisitExpr(ctx *parser.ExprContext) interface{} {
|
func (p *policyVisitor) VisitExpr(ctx *parser.ExprContext) any {
|
||||||
f := new(netmap.Filter)
|
f := new(netmap.Filter)
|
||||||
if flt := ctx.GetFilter(); flt != nil {
|
if flt := ctx.GetFilter(); flt != nil {
|
||||||
f.SetName(flt.GetText())
|
f.SetName(flt.GetText())
|
||||||
|
|
|
@ -26,7 +26,7 @@ type NNS struct {
|
||||||
nnsContract util.Uint160
|
nnsContract util.Uint160
|
||||||
|
|
||||||
invoker interface {
|
invoker interface {
|
||||||
Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error)
|
Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ type testNeoClient struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *testNeoClient) Call(contract util.Uint160, operation string, params ...interface{}) (*result.Invoke, error) {
|
func (x *testNeoClient) Call(contract util.Uint160, operation string, params ...any) (*result.Invoke, error) {
|
||||||
var domain string
|
var domain string
|
||||||
|
|
||||||
require.Equal(x.t, x.expectedContract, contract)
|
require.Equal(x.t, x.expectedContract, contract)
|
||||||
|
@ -49,7 +49,7 @@ type brokenArrayStackItem struct {
|
||||||
stackitem.Item
|
stackitem.Item
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x brokenArrayStackItem) Value() interface{} {
|
func (x brokenArrayStackItem) Value() any {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue