Exemple #1
0
func Mkfile(
	c rpc.Client, l rpc.Logger, ret interface{}, key string, hasKey bool, fsize int64, extra *PutExtra) (err error) {

	url := UP_HOST + "/mkfile/" + strconv.FormatInt(fsize, 10)

	if extra.MimeType != "" {
		url += "/mimeType/" + encode(extra.MimeType)
	}
	if hasKey {
		url += "/key/" + encode(key)
	}
	for k, v := range extra.Params {
		url += fmt.Sprintf("/%s/%s", k, encode(v))
	}

	buf := make([]byte, 0, 176*len(extra.Progresses))
	for _, prog := range extra.Progresses {
		buf = append(buf, prog.Ctx...)
		buf = append(buf, ',')
	}
	if len(buf) > 0 {
		buf = buf[:len(buf)-1]
	}

	return c.CallWith(l, ret, url, "application/octet-stream", bytes.NewReader(buf), len(buf))
}
func TestBasic(t *testing.T) {

	svr := new(Service)
	svr.RegisterRoute()

	mockhttp.ListenAndServe("foo.com", nil)

	c := rpc.Client{mockhttp.DefaultClient}
	{
		var foo FooRet
		err := c.Call(nil, &foo, "http://foo.com/foo")
		if err != nil {
			t.Fatal("call foo failed:", err)
		}
		if foo.A != 1 || foo.B != "foo.com" || foo.C != "/foo" {
			t.Fatal("call foo: invalid ret")
		}
		fmt.Println(foo)
	}
	{
		var ret map[string]string
		err := c.Call(nil, &ret, "http://foo.com/bar")
		if err != nil {
			t.Fatal("call foo failed:", err)
		}
		if ret["foo"] != "1" || ret["bar"] != "2" {
			t.Fatal("call bar: invalid ret")
		}
		fmt.Println(ret)
	}
}
Exemple #3
0
func Blockput(
	c rpc.Client, l rpc.Logger, ret *BlkputRet, body io.Reader, size int) error {

	url := ret.Host + "/bput/" + ret.Ctx + "/" + strconv.FormatUint(uint64(ret.Offset), 10)
	return c.CallWith(l, ret, url, "application/octet-stream", body, size)
}
Exemple #4
0
func Mkblock(
	c rpc.Client, l rpc.Logger, ret *BlkputRet, blockSize int, body io.Reader, size int) error {

	return c.CallWith(l, ret, UP_HOST+"/mkblk/"+strconv.Itoa(blockSize), "application/octet-stream", body, size)
}