replace interface{} instead of any

This commit is contained in:
thinkerou 2023-02-27 10:34:19 +08:00
parent b75f1bf3b3
commit 7f7ab66332
7 changed files with 12 additions and 12 deletions

View File

@ -15,7 +15,7 @@ import (
// EnableDecoderUseNumber is used to call the UseNumber method on the JSON // EnableDecoderUseNumber is used to call the UseNumber method on the JSON
// Decoder instance. UseNumber causes the Decoder to unmarshal a number into an // Decoder instance. UseNumber causes the Decoder to unmarshal a number into an
// interface{} as a Number instead of as a float64. // any as a Number instead of as a float64.
var EnableDecoderUseNumber = false var EnableDecoderUseNumber = false
// EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method // EnableDecoderDisallowUnknownFields is used to call the DisallowUnknownFields method

View File

@ -652,7 +652,7 @@ func (c *Context) BindYAML(obj any) error {
} }
// BindTOML is a shortcut for c.MustBindWith(obj, binding.TOML). // BindTOML is a shortcut for c.MustBindWith(obj, binding.TOML).
func (c *Context) BindTOML(obj interface{}) error { func (c *Context) BindTOML(obj any) error {
return c.MustBindWith(obj, binding.TOML) return c.MustBindWith(obj, binding.TOML)
} }
@ -717,7 +717,7 @@ func (c *Context) ShouldBindYAML(obj any) error {
} }
// ShouldBindTOML is a shortcut for c.ShouldBindWith(obj, binding.TOML). // ShouldBindTOML is a shortcut for c.ShouldBindWith(obj, binding.TOML).
func (c *Context) ShouldBindTOML(obj interface{}) error { func (c *Context) ShouldBindTOML(obj any) error {
return c.ShouldBindWith(obj, binding.TOML) return c.ShouldBindWith(obj, binding.TOML)
} }
@ -995,7 +995,7 @@ func (c *Context) YAML(code int, obj any) {
} }
// TOML serializes the given struct as TOML into the response body. // TOML serializes the given struct as TOML into the response body.
func (c *Context) TOML(code int, obj interface{}) { func (c *Context) TOML(code int, obj any) {
c.Render(code, render.TOML{Data: obj}) c.Render(code, render.TOML{Data: obj})
} }

View File

@ -37,7 +37,7 @@ var errTestRender = errors.New("TestRender")
// Unit tests TODO // Unit tests TODO
// func (c *Context) File(filepath string) { // func (c *Context) File(filepath string) {
// func (c *Context) Negotiate(code int, config Negotiate) { // func (c *Context) Negotiate(code int, config Negotiate) {
// BAD case: func (c *Context) Render(code int, render render.Render, obj ...interface{}) { // BAD case: func (c *Context) Render(code int, render render.Render, obj ...any) {
// test that information is not leaked when reusing Contexts (using the Pool) // test that information is not leaked when reusing Contexts (using the Pool)
func createMultipartRequest() *http.Request { func createMultipartRequest() *http.Request {

View File

@ -21,7 +21,7 @@ import (
// TODO // TODO
// func debugRoute(httpMethod, absolutePath string, handlers HandlersChain) { // func debugRoute(httpMethod, absolutePath string, handlers HandlersChain) {
// func debugPrint(format string, values ...interface{}) { // func debugPrint(format string, values ...any) {
func TestIsDebugging(t *testing.T) { func TestIsDebugging(t *testing.T) {
SetMode(DebugMode) SetMode(DebugMode)

View File

@ -13,7 +13,7 @@ import (
// BindWith binds the passed struct pointer using the specified binding engine. // BindWith binds the passed struct pointer using the specified binding engine.
// See the binding package. // See the binding package.
func (c *Context) BindWith(obj any, b binding.Binding) error { func (c *Context) BindWith(obj any, b binding.Binding) error {
log.Println(`BindWith(\"interface{}, binding.Binding\") error is going to log.Println(`BindWith(\"any, binding.Binding\") error is going to
be deprecated, please check issue #662 and either use MustBindWith() if you be deprecated, please check issue #662 and either use MustBindWith() if you
want HTTP 400 to be automatically returned if any error occur, or use want HTTP 400 to be automatically returned if any error occur, or use
ShouldBindWith() if you need to manage the error.`) ShouldBindWith() if you need to manage the error.`)

View File

@ -425,7 +425,7 @@ func main() {
r.Use(gin.Logger()) r.Use(gin.Logger())
// Recovery middleware recovers from any panics and writes a 500 if there was one. // Recovery middleware recovers from any panics and writes a 500 if there was one.
r.Use(gin.CustomRecovery(func(c *gin.Context, recovered interface{}) { r.Use(gin.CustomRecovery(func(c *gin.Context, recovered any) {
if err, ok := recovered.(string); ok { if err, ok := recovered.(string); ok {
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err)) c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
} }
@ -996,7 +996,7 @@ curl -X POST -v --form name=user --form "avatar=@./avatar.png" http://localhost:
func main() { func main() {
r := gin.Default() r := gin.Default()
// gin.H is a shortcut for map[string]interface{} // gin.H is a shortcut for map[string]any
r.GET("/someJSON", func(c *gin.Context) { r.GET("/someJSON", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK}) c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
}) })
@ -1961,7 +1961,7 @@ func (customerBinding) Name() string {
return "form" return "form"
} }
func (customerBinding) Bind(req *http.Request, obj interface{}) error { func (customerBinding) Bind(req *http.Request, obj any) error {
if err := req.ParseForm(); err != nil { if err := req.ParseForm(); err != nil {
return err return err
} }
@ -1976,7 +1976,7 @@ func (customerBinding) Bind(req *http.Request, obj interface{}) error {
return validate(obj) return validate(obj)
} }
func validate(obj interface{}) error { func validate(obj any) error {
if binding.Validator == nil { if binding.Validator == nil {
return nil return nil
} }

View File

@ -50,7 +50,7 @@ func WrapH(h http.Handler) HandlerFunc {
} }
} }
// H is a shortcut for map[string]interface{} // H is a shortcut for map[string]any
type H map[string]any type H map[string]any
// MarshalXML allows type H to be used with xml.Marshal. // MarshalXML allows type H to be used with xml.Marshal.