Closed seanchann closed 7 years ago
I have zero idea what you are trying to do here, or what your point is.
First of all - what is the bug? You need to put a reproducer that I can run with "go run main.go" or "go test", then tell me what you expect to get, and then tell me what you receive. This way, I can reproduce your error and fix, or I can advise why what you saw is correct and close as a User Error.
complete test code:
package main
import (
"fmt"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"github.com/ugorji/go/codec"
)
type User struct {
unversioned.TypeMeta `json:",inline"`
api.ObjectMeta `json:"metadata,omitempty"`
Spec interface{} `json:"spec,omitempty"`
}
func main() {
user:= &User{}
var ss = `{"apiVersion":"v1","kind":"User","metadata":{"annotations":{"area_id":"800000","city":"深圳市","city_id":"440300","cnISP":"cnISPCTCC","country":"ä¸å›½","country_id":"CN","county_id":"-1","isp_id":"100017","proto":null,"publicip":"113.86.18.48","refreshTime":"2016-11-20 08:00:16.468426102 +0000 UTC","region_id":"440000","userSpace":"develop","version":"03.00.00.69","wanip":null},"creationTimestamp":"2016-11-20T08:53:55Z","name":"78a351157a5c","uid":"de87bf5a-aefe-11e6-ac40-00155d3d7203"},"spec":{"detailInfo":{"description":"78:A3:51:15:7A:5C","downloadTraffic":2.79152799e+08,"email":"78a351157a5c@gmail.com","enableOTA":true,"expireTime":"2017-10-19T17:11:29Z","id":108,"managePasswd":"ca709d5580bc7ec8327133234424e982c74","name":"78a351157a5c","passwd":"95067bef91746c3a390f90bdf3445d6a7e9","regIPAddr":"54.191.184.140","regTime":"2016-11-20T08:52:12Z","status":true,"trafficLimit":5.36870912e+10,"uploadTraffic":6.911085e+06},"userService":{"nodes":{"06df9e50cdd7":{"host":"199.203.99.67","user":{"downloadTraffic":2.6743306e+07,"enableOTA":true,"id":108,"method":"aes-256-cfb","name":"78a351157a5c","password":"95067bef91746c3a3904552340bd10d6a7e9","port":33185,"uploadTraffic":636262}},"faadf65a6352":{"host":"104.206.61.91","user":{"downloadTraffic":3.1574614e+07,"enableOTA":true,"id":108,"method":"aes-256-cfb","name":"78a351157a5c","password":"95067bef9174ldkajf23390f90bd10d6a7e9","port":40674,"uploadTraffic":758111}}}}}}`
var s = []byte(ss)
var h codec.JsonHandle
err := codec.NewDecoderBytes(s, &h).Decode(user)
fmt.Printf("err:%v User is now: %v of type: %T\n", err, user, user)
}
Please give me a standalone reproducer that didn't include me downloading and third-party packages, then state output you get and West you expect. Thanks.
package main
import (
"fmt"
"github.com/ugorji/go/codec"
)
type TypeMeta struct {
Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`
APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt,name=apiVersion"`
}
type ObjectMeta struct {
Name string `json:"name,omitempty"`
GenerateName string `json:"generateName,omitempty"`
Namespace string `json:"namespace,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
UID interface{} `json:"uid,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
Generation int64 `json:"generation,omitempty"`
CreationTimestamp interface{} `json:"creationTimestamp,omitempty"`
DeletionTimestamp interface{} `json:"deletionTimestamp,omitempty"`
DeletionGracePeriodSeconds *int64 `json:"deletionGracePeriodSeconds,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
OwnerReferences interface{} `json:"ownerReferences,omitempty"`
Finalizers []string `json:"finalizers,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
}
type User struct {
TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec interface{} `json:"spec,omitempty"`
}
func main() {
user := &User{}
var ss = `{"apiVersion":"v1","kind":"User","metadata":{"annotations":{"area_id":"800000","city":"深圳市","city_id":"440300","cnISP":"cnISPCTCC","country":"ä¸å›½","country_id":"CN","county_id":"-1","isp_id":"100017","proto":null,"publicip":"113.86.18.48","refreshTime":"2016-11-20 08:00:16.468426102 +0000 UTC","region_id":"440000","userSpace":"develop","version":"03.00.00.69","wanip":null},"creationTimestamp":"2016-11-20T08:53:55Z","name":"78a351157a5c","uid":"de87bf5a-aefe-11e6-ac40-00155d3d7203"},"spec":{"detailInfo":{"description":"78:A3:51:15:7A:5C","downloadTraffic":2.79152799e+08,"email":"78a351157a5c@gmail.com","enableOTA":true,"expireTime":"2017-10-19T17:11:29Z","id":108,"managePasswd":"ca709d5580bc7ec8327133234424e982c74","name":"78a351157a5c","passwd":"95067bef91746c3a390f90bdf3445d6a7e9","regIPAddr":"54.191.184.140","regTime":"2016-11-20T08:52:12Z","status":true,"trafficLimit":5.36870912e+10,"uploadTraffic":6.911085e+06},"userService":{"nodes":{"06df9e50cdd7":{"host":"199.203.99.67","user":{"downloadTraffic":2.6743306e+07,"enableOTA":true,"id":108,"method":"aes-256-cfb","name":"78a351157a5c","password":"95067bef91746c3a3904552340bd10d6a7e9","port":33185,"uploadTraffic":636262}},"faadf65a6352":{"host":"104.206.61.91","user":{"downloadTraffic":3.1574614e+07,"enableOTA":true,"id":108,"method":"aes-256-cfb","name":"78a351157a5c","password":"95067bef9174ldkajf23390f90bd10d6a7e9","port":40674,"uploadTraffic":758111}}}}}}`
var s = []byte(ss)
var h codec.JsonHandle
err := codec.NewDecoderBytes(s, &h).Decode(user)
fmt.Printf("err:%v User is now: %v of type: %T\n", err, user, user)
}
hi: add printf in code: