Chore: use any rather than interface{} (#74066)
This commit is contained in:
+2
-2
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// Bind deserializes JSON payload from the request
|
||||
func Bind(req *http.Request, v interface{}) error {
|
||||
func Bind(req *http.Request, v any) error {
|
||||
if req.Body != nil {
|
||||
m, _, err := mime.ParseMediaType(req.Header.Get("Content-type"))
|
||||
if err != nil {
|
||||
@@ -33,7 +33,7 @@ type Validator interface {
|
||||
Validate() error
|
||||
}
|
||||
|
||||
func validate(obj interface{}) error {
|
||||
func validate(obj any) error {
|
||||
// First check if obj is nil, because we cannot validate those.
|
||||
if obj == nil {
|
||||
return nil
|
||||
|
||||
@@ -22,7 +22,7 @@ type StructWithPrivateFields struct {
|
||||
}
|
||||
|
||||
type StructWithInterface struct {
|
||||
A interface{} `binding:"Required"`
|
||||
A any `binding:"Required"`
|
||||
}
|
||||
type StructWithSliceInts struct {
|
||||
A []int `binding:"Required"`
|
||||
@@ -31,7 +31,7 @@ type StructWithSliceStructs struct {
|
||||
A []StructWithInt `binding:"Required"`
|
||||
}
|
||||
type StructWithSliceInterfaces struct {
|
||||
A []interface{} `binding:"Required"`
|
||||
A []any `binding:"Required"`
|
||||
}
|
||||
type StructWithStruct struct {
|
||||
A StructWithInt `binding:"Required"`
|
||||
@@ -64,7 +64,7 @@ func (sv *StructWithPointerValidation) Validate() error {
|
||||
func TestValidationSuccess(t *testing.T) {
|
||||
var nilInterface *StructWithPointerValidation
|
||||
|
||||
for _, x := range []interface{}{
|
||||
for _, x := range []any{
|
||||
nil,
|
||||
42,
|
||||
"foo",
|
||||
@@ -74,7 +74,7 @@ func TestValidationSuccess(t *testing.T) {
|
||||
StructWithPrivateFields{12, 0},
|
||||
StructWithInterface{"foo"},
|
||||
StructWithSliceInts{[]int{1, 2, 3}},
|
||||
StructWithSliceInterfaces{[]interface{}{1, 2, 3}},
|
||||
StructWithSliceInterfaces{[]any{1, 2, 3}},
|
||||
StructWithSliceStructs{[]StructWithInt{{1}, {2}}},
|
||||
StructWithStruct{StructWithInt{3}},
|
||||
StructWithStructPointer{&StructWithInt{3}},
|
||||
@@ -88,7 +88,7 @@ func TestValidationSuccess(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestValidationFailure(t *testing.T) {
|
||||
for i, x := range []interface{}{
|
||||
for i, x := range []any{
|
||||
StructWithInt{0},
|
||||
StructWithPrimitives{0, "foo", true, 12.34},
|
||||
StructWithPrimitives{42, "", true, 12.34},
|
||||
@@ -102,7 +102,7 @@ func TestValidationFailure(t *testing.T) {
|
||||
StructWithSliceStructs{[]StructWithInt{}},
|
||||
StructWithSliceStructs{[]StructWithInt{{0}, {2}}},
|
||||
StructWithSliceStructs{[]StructWithInt{{2}, {0}}},
|
||||
StructWithSliceInterfaces{[]interface{}{}},
|
||||
StructWithSliceInterfaces{[]any{}},
|
||||
StructWithSliceInterfaces{nil},
|
||||
StructWithStruct{StructWithInt{}},
|
||||
StructWithStruct{StructWithInt{0}},
|
||||
|
||||
+2
-2
@@ -102,7 +102,7 @@ const (
|
||||
)
|
||||
|
||||
// HTML renders the HTML with default template set.
|
||||
func (ctx *Context) HTML(status int, name string, data interface{}) {
|
||||
func (ctx *Context) HTML(status int, name string, data any) {
|
||||
ctx.Resp.Header().Set(headerContentType, contentTypeHTML)
|
||||
ctx.Resp.WriteHeader(status)
|
||||
if err := ctx.template.ExecuteTemplate(ctx.Resp, name, data); err != nil {
|
||||
@@ -113,7 +113,7 @@ func (ctx *Context) HTML(status int, name string, data interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func (ctx *Context) JSON(status int, data interface{}) {
|
||||
func (ctx *Context) JSON(status int, data any) {
|
||||
ctx.Resp.Header().Set(headerContentType, contentTypeJSON)
|
||||
ctx.Resp.WriteHeader(status)
|
||||
enc := json.NewEncoder(ctx.Resp)
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ func Version() string {
|
||||
// Handler can be any callable function.
|
||||
// Macaron attempts to inject services into the handler's argument list,
|
||||
// and panics if an argument could not be fulfilled via dependency injection.
|
||||
type Handler interface{}
|
||||
type Handler any
|
||||
|
||||
//go:linkname hack_wrap github.com/grafana/grafana/pkg/api/response.wrap_handler
|
||||
func hack_wrap(Handler) http.HandlerFunc
|
||||
|
||||
Reference in New Issue
Block a user