Esempio n. 1
0
func main() {
	var reply Reply
	err := httprpc.CallJson("1.0", "http://localhost:9000/rpc", "HelloService.Say", &Args{"kevin"}, &reply)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(reply.Message)
}
Esempio n. 2
0
func PauseAll() (string, error) {
	method := "aria2.pauseAll"
	paramArr := make([]string, 0)
	var reply string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return "", err
	}
	return reply, nil
}
Esempio n. 3
0
func GetGlobalStat() (map[string]interface{}, error) {
	method := "aria2.getGlobalStat"
	paramArr := make([]interface{}, 0)
	var reply = make(map[string]interface{})
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return nil, err
	}
	return reply, nil
}
Esempio n. 4
0
func GetGlobalOption() (map[string]interface{}, error) {
	method := "aria2.getGlobalOption"
	paramArr := make([]interface{}, 1)
	paramArr[0] = "token:" + RpcSecret
	var reply = make(map[string]interface{})
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return nil, err
	}
	return reply, nil
}
Esempio n. 5
0
func UnpauseAll() (string, error) {
	method := "aria2.unpauseAll"
	paramArr := make([]string, 1)
	paramArr[0] = "token:" + RpcSecret
	var reply string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return "", err
	}
	return reply, nil
}
Esempio n. 6
0
func Unpause(gid string) (string, error) {
	method := "aria2.unpause"
	paramArr := make([]interface{}, 1)
	paramArr[0] = gid
	var replyGID string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &replyGID)
	if err != nil {
		return "", err
	}
	return replyGID, nil
}
Esempio n. 7
0
func ChangeGlobalOption(params map[string]string) (string, error) {
	method := "aria2.changeGlobalOption"
	paramArr := make([]interface{}, 0)
	paramArr = append(paramArr, params)

	var reply string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return "", err
	}
	return reply, nil
}
Esempio n. 8
0
func GetActive(keys []string) ([]map[string]interface{}, error) {
	method := "aria2.tellActive"
	paramArr := make([]interface{}, 0)
	if keys != nil && len(keys) > 0 {
		paramArr = append(paramArr, keys)
	}
	var reply = make([]map[string]interface{}, 10)
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return nil, err
	}
	return reply, nil
}
Esempio n. 9
0
func ChangeOption(gid string, params map[string]string) (string, error) {
	method := "aria2.changeOption"
	paramArr := make([]interface{}, 2)
	paramArr[0] = "token:" + RpcSecret
	paramArr[1] = gid
	paramArr = append(paramArr, params)

	var reply string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return "", err
	}
	return reply, nil
}
Esempio n. 10
0
func GetStatus(gid string, keys []string) (map[string]interface{}, error) {
	method := "aria2.tellStatus"
	paramArr := make([]interface{}, 1)
	paramArr[0] = gid
	if keys != nil && len(keys) > 0 {
		paramArr = append(paramArr, keys)
	}
	var reply = make(map[string]interface{})
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return nil, err
	}
	return reply, nil
}
Esempio n. 11
0
func GetStopped(offset, num int, keys []string) ([]map[string]interface{}, error) {
	method := "aria2.tellStopped"
	paramArr := make([]interface{}, 2)
	paramArr[0] = offset
	paramArr[1] = num
	if keys != nil && len(keys) > 0 {
		paramArr = append(paramArr, keys)
	}
	var reply = make([]map[string]interface{}, 10)
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &reply)
	if err != nil {
		return nil, err
	}
	return reply, nil
}
Esempio n. 12
0
func Pause(gid string, force bool) (string, error) {
	var method string
	if force {
		method = "aria2.forcePause"
	} else {
		method = "aria2.pause"
	}
	paramArr := make([]interface{}, 1)
	paramArr[0] = gid
	var replyGID string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &replyGID)
	if err != nil {
		return "", err
	}
	return replyGID, nil
}
Esempio n. 13
0
func Remove(gid string, force bool) (string, error) {
	var method string
	if force {
		method = "aria2.forceRemove"
	} else {
		method = "aria2.remove"
	}
	paramArr := make([]interface{}, 2)
	paramArr[0] = "token:" + RpcSecret
	paramArr[1] = gid
	var replyGID string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &replyGID)
	if err != nil {
		return "", err
	}
	return replyGID, nil
}
Esempio n. 14
0
func AddUri(uri string, params map[string]interface{}) (string, error) {
	method := "aria2.addUri"
	paramArr := make([]interface{}, 1)
	uris := make([]string, 1)
	uris[0] = uri
	paramArr[0] = uris
	if params != nil {
		paramArr = append(paramArr, params)
	}

	var replyGID string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &replyGID)
	if err != nil {
		return "", err
	}
	return replyGID, nil
}
Esempio n. 15
0
func AddTorrent(path string) (string, error) {
	file, openFileErr := os.Open(path)
	if openFileErr != nil {
		return "", nil
	}

	fileBytes, readError := ioutil.ReadAll(bufio.NewReader(file))
	if readError != nil {
		return "", readError
	}
	coder := base64.StdEncoding
	encoded := coder.EncodeToString(fileBytes)

	method := "aria2.addTorrent"
	paramArr := make([]interface{}, 1)
	paramArr[0] = encoded
	var replyGID string
	err := httprpc.CallJson(RpcVersion, RpcUrl, method, paramArr, &replyGID)
	if err != nil {
		return "", err
	}
	return replyGID, nil
}