less main.go
output:
```
package main
import (
"reflect"
"net/url"
"fmt"
)
type User struct {
Id uint64 `json:"id"`
No *string `json:"no"`
Identity string `json:"identity"`
Head url.URL `json:"head"`
}
func main() {
t := reflect.TypeOf(User{})
u := reflect.New(t).Elem().Interface()
fmt.Printf("u is %T, %v\n", u, u)
}
```
go version
output:
go version go1.5.2 darwin/amd64
go build main.go
correct
./main
output:
u is main.User, {0 <nil> { <nil> }}
what the matter?? why u object only third field? the User struct include four field!
In my really project, I find the created object's field's type is incorrect
Aucun commentaire:
Enregistrer un commentaire