示例#1
0
文件: byte.go 项目: eaciit/labs
func main() {
	type Obj struct {
		AA string
		BB string
	}
	data := []Obj{
		{"A", "B"},
		{"C", "D"},
		{"E", "F"}}

	b := toolkit.GetEncodeByte(data)
	fmt.Printf("Data is : %v\nString: %v\nLen: %d\n", b, string(b), len(b))
	var decoded Obj
	toolkit.DecodeByte(b, &decoded)
	fmt.Printf("Decoded: %v \n\n", decoded)

	//b = []byte(fmt.Sprint(data))
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.LittleEndian, data)
	b = buf.Bytes()
	fmt.Printf("Data is : %v\nString: %v\nLen: %d\n", b, string(b), len(b))
	eread := binary.Read(buf, binary.LittleEndian, &decoded)
	if eread != nil {
		fmt.Printf("Unable to decode. %s \n", eread.Error())
	} else {
		fmt.Printf("Decoded: %v \n\n", decoded)
	}
}
示例#2
0
func TestPut(t *testing.T) {
	if e := getToken(); e != nil {
		//he(t, e)
		//return
	}

	surl := restPrefix + "/put"
	for i := 1; i <= 1000; i++ {
		randomTxt := createRandomString(toolkit.RandInt(22) + 10)
		data := struct {
			Token string
			Data  string
		}{
			token,
			randomTxt,
		}

		fmt.Printf("Saving %d value %s", i, data.Data)

		r, e := toolkit.HttpCall(surl, "XPUT", toolkit.GetEncodeByte(data), nil)
		//e = nil
		if e != nil {
			fmt.Printf("... Fail: %s \n", e.Error())
		} else {
			if r.StatusCode != 200 {
				fmt.Printf("... Fail: %d %s \n", r.StatusCode, r.Status)
			} else {
				fmt.Println("...Done")
			}
			fmt.Println("...Done")
		}
	}
}