master
go 36 lines 623 Bytes
Raw
1 package rpc
2
3 import (
4 "context"
5 "io"
6 "strings"
7 )
8
9 type Request struct {
10 Ctx context.Context
11 ApiBase string
12 Command string
13 Args []string
14 Opts map[string]string
15 Body io.Reader
16 Headers map[string]string
17 }
18
19 func NewRequest(ctx context.Context, url, command string, args ...string) *Request {
20 if !strings.HasPrefix(url, "http") {
21 url = "http://" + url
22 }
23
24 opts := map[string]string{
25 "encoding": "json",
26 "stream-channels": "true",
27 }
28 return &Request{
29 Ctx: ctx,
30 ApiBase: url + "/api/v0",
31 Command: command,
32 Args: args,
33 Opts: opts,
34 Headers: make(map[string]string),
35 }
36 }