-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util/gconv: After conversion, the interface{} type becomes *interface {} #3731
Comments
package main
import (
"fmt"
"github.com/gogf/gf/v2/util/gconv"
)
func main() {
dataMap := map[string]any{
"doc": map[string]any{
"craft": nil,
},
}
var args *Data
err := gconv.Struct(dataMap, &args)
if err != nil {
panic(err)
}
fmt.Printf("args: %T\n", args.Doc["craft"])
fmt.Printf("dataMap: %T\n", dataMap["doc"].(map[string]any)["craft"])
}
type Data struct {
Doc map[string]interface{} `json:"doc"`
} Shouldn't your expected output here be |
In Go, when you assign nil to a variable of type interface{}, that variable is actually an interface{} pointer to nil. |
func main() {
req := map[string]any{
"id": "123",
"doc": map[string]any{
"craft": nil,
},
"fields": []string{"_id"},
}
var args *UpdateByIdReq
err := gconv.Struct(req, &args)
if err != nil {
panic(err)
}
var abc interface{}
abc = nil
fmt.Printf("%T, %T", args.Doc["craft"], abc)
} output
If I check args.Doc["craft"] == nil here, it returns false. Isn't this counterintuitive? |
You should expect the output to be |
yes |
yes |
my fix should be correct |
Is this a bug? |
yes |
Thank you. My expected type is |
Thank you |
…hub.com:gogf/gf into feature/action-1.23 * 'feature/action-1.23' of github.com:gogf/gf: feat: version v2.7.3 (#3763) perf(util/gconv): add cache logic to enhance performance (#3673) fix(contrib/drivers/pgsql): fix insert error when data struct field has nil in PgSQL (#3679) fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732) fix(contrib/drivers/pgsql): #3671 fix invalid pgsql insert json type (#3742) refactor(nacos-registry): use official nacos sdk instead of the third-party nacos sdk (#3745) * 'feature/action-1.23' of github.com:gogf/gf: feat: version v2.7.3 (#3763) perf(util/gconv): add cache logic to enhance performance (#3673) fix(contrib/drivers/pgsql): fix insert error when data struct field has nil in PgSQL (#3679) fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732) fix(contrib/drivers/pgsql): #3671 fix invalid pgsql insert json type (#3742) refactor(nacos-registry): use official nacos sdk instead of the third-party nacos sdk (#3745)
Go version
go version go1.18 windows/amd64
GoFrame version
v2.7.2
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
What did you see happen?
输出
*interface {}
What did you expect to see?
应该是
interface{}
The text was updated successfully, but these errors were encountered: