package douyu import ( "fmt" jsoniter "github.com/json-iterator/go" "github.com/mitchellh/mapstructure" "live-gateway/douyu/msg_handler" "testing" ) func TestDecodeData(t *testing.T) { codec := NewCodecDouyu() // type@=chatmsg/rid@=58839/ct@=8/hashid@=9LA18ePx4dqW/nn@=test/txt@=666/cid@=1111/ic@=icon/sahf@=0/level@=1/nl@=0/nc@=0/cmt@=0/gt@=0/col@=0/rg@=0/pg@=0/dlv@=0/dc@=0/bdlv@=0/gatin@=0/chtin@=0/repin@=0/bnn@=test/bl@=0/brid@=58839/hc@=0/ol@=0/rev@=0/hl@=0/ifs@=0/p2p@=0/el@=eid@AA=1@ASetp@AA=1@ASsc@AA=1@AS/ // type@=chatmsg/rid@=3484/ct@=14/uid@=53882869/nn@=.........................../txt@=......................../cid@=0e7aca52aede49eb2e9a2a0100000000/ic@=avatar@Sdefault@S11/level@=30/sahf@=0/col@=1/cst@=1657543712943/bnn@=....../bl@=18/brid@=3484/hc@=709494ed025488b6f77db71902e124cd/diaf@=1/hl@=1/ifs@=1/el@=/lk@=/fl@=18/dms@=3/pdg@=54/pdk@=87/ext@=/. var wsEntry interface{} = &WsEntry{ data: []byte("type@=chatmsg/rid@=3484/ct@=14/uid@=53882869/nn@=.........................../txt@=......................../cid@=0e7aca52aede49eb2e9a2a0100000000/ic@=avatar@Sdefault@S11/level@=30/sahf@=0/col@=1/cst@=1657543712943/bnn@=....../bl@=18/brid@=3484/hc@=709494ed025488b6f77db71902e124cd/diaf@=1/hl@=1/ifs@=1/el@=/lk@=/fl@=18/dms@=3/pdg@=54/pdk@=87/ext@=/."), } var err error wsEntry, err = codec.Decode(wsEntry) if err != nil { panic(err) } var dm msg_handler.MsgDanmaku err = mapstructure.Decode(wsEntry.(*WsEntry).MapData, &dm) var cmd struct { CMD string `json:"cmd"` } jsoniter.Unmarshal([]byte(`{"cmd":"stringcmd"}`), &cmd) fmt.Printf("%+v", wsEntry) }