mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-17 23:16:11 +08:00
37 lines
623 B
Go
37 lines
623 B
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
type Request struct {
|
|
Ctx context.Context
|
|
ApiBase string
|
|
Command string
|
|
Args []string
|
|
Opts map[string]string
|
|
Body io.Reader
|
|
Headers map[string]string
|
|
}
|
|
|
|
func NewRequest(ctx context.Context, url, command string, args ...string) *Request {
|
|
if !strings.HasPrefix(url, "http") {
|
|
url = "http://" + url
|
|
}
|
|
|
|
opts := map[string]string{
|
|
"encoding": "json",
|
|
"stream-channels": "true",
|
|
}
|
|
return &Request{
|
|
Ctx: ctx,
|
|
ApiBase: url + "/api/v0",
|
|
Command: command,
|
|
Args: args,
|
|
Opts: opts,
|
|
Headers: make(map[string]string),
|
|
}
|
|
}
|