don't make api base configurable
This commit is contained in:
parent
f3c98d4153
commit
f7ef780926
@ -21,8 +21,6 @@ import (
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
// HTTP is the client used to make requests.
|
// HTTP is the client used to make requests.
|
||||||
HTTP http.Client
|
HTTP http.Client
|
||||||
// APIBase is the path under which the Chord API is served.
|
|
||||||
APIBase string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindSuccessor asks s to find a value and the peer that owns it.
|
// FindSuccessor asks s to find a value and the peer that owns it.
|
||||||
@ -34,7 +32,7 @@ func (cl *Client) FindSuccessor(ctx context.Context, s chord.Peer, id chord.ID)
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "find", id.String()),
|
Path: path.Join("/find", id.String()),
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -58,7 +56,7 @@ func (cl *Client) Get(ctx context.Context, s chord.Peer, id chord.ID) (string, e
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "key", id.String()),
|
Path: path.Join("/key", id.String()),
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,7 +82,7 @@ func (cl *Client) Set(ctx context.Context, s chord.Peer, id chord.ID, v string)
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "key", id.String()),
|
Path: path.Join("/key", id.String()),
|
||||||
}
|
}
|
||||||
body := strings.NewReader(base64.StdEncoding.EncodeToString([]byte(v)))
|
body := strings.NewReader(base64.StdEncoding.EncodeToString([]byte(v)))
|
||||||
req, err := http.NewRequestWithContext(ctx, "POST", url.String(), body)
|
req, err := http.NewRequestWithContext(ctx, "POST", url.String(), body)
|
||||||
@ -112,7 +110,7 @@ func (cl *Client) Notify(ctx context.Context, n *chord.Node, s chord.Peer) error
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "pred"),
|
Path: path.Join("/pred"),
|
||||||
RawQuery: url.Values{"p": {self.String()}}.Encode(),
|
RawQuery: url.Values{"p": {self.String()}}.Encode(),
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "POST", url.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, "POST", url.String(), nil)
|
||||||
@ -139,7 +137,7 @@ func (cl *Client) Neighbors(ctx context.Context, p chord.Peer) (pred chord.Peer,
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "neighbors"),
|
Path: path.Join("/neighbors"),
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -188,7 +186,7 @@ func (cl *Client) Bye(ctx context.Context, p, n chord.Peer, succ []chord.Peer) e
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase, "bye"),
|
Path: path.Join("/bye"),
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "POST", url.String(), bytes.NewReader(b))
|
req, err := http.NewRequestWithContext(ctx, "POST", url.String(), bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,7 +212,7 @@ func (cl *Client) SayBye(ctx context.Context, p chord.Peer) error {
|
|||||||
url := url.URL{
|
url := url.URL{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Host: addr.String(),
|
Host: addr.String(),
|
||||||
Path: path.Join("/", cl.APIBase),
|
Path: path.Join("/"),
|
||||||
}
|
}
|
||||||
req, err := http.NewRequestWithContext(ctx, "DELETE", url.String(), nil)
|
req, err := http.NewRequestWithContext(ctx, "DELETE", url.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user