Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 843379e

Browse files
imeoercarmark
authored andcommitted
support multiple region for func
1 parent 289e82c commit 843379e

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

api/client/func.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func (cli *DockerCli) CmdFuncCall(args ...string) error {
400400
}
401401
}
402402

403-
body, err := cli.client.FuncCall(context.Background(), name, stdin, *sync)
403+
body, err := cli.client.FuncCall(context.Background(), cli.region, name, stdin, *sync)
404404
if err != nil {
405405
return err
406406
}
@@ -435,7 +435,7 @@ func (cli *DockerCli) CmdFuncGet(args ...string) error {
435435

436436
callId := cmd.Arg(0)
437437

438-
body, err := cli.client.FuncGet(context.Background(), callId, *wait)
438+
body, err := cli.client.FuncGet(context.Background(), cli.region, callId, *wait)
439439
if err != nil {
440440
return err
441441
}
@@ -463,7 +463,7 @@ func (cli *DockerCli) CmdFuncLogs(args ...string) error {
463463
name := cmd.Arg(0)
464464
name = strings.Replace(name, "/", "", -1)
465465

466-
reader, err := cli.client.FuncLogs(context.Background(), name, *callId, *follow, *tail)
466+
reader, err := cli.client.FuncLogs(context.Background(), cli.region, name, *callId, *follow, *tail)
467467
if err != nil {
468468
return err
469469
}
@@ -503,7 +503,6 @@ func (cli *DockerCli) CmdFuncLogs(args ...string) error {
503503
}
504504
}
505505
}
506-
return nil
507506
}
508507

509508
// CmdFuncStatus Status the return of a func call
@@ -520,7 +519,7 @@ func (cli *DockerCli) CmdFuncStatus(args ...string) error {
520519
name := cmd.Arg(0)
521520
name = strings.Replace(name, "/", "", -1)
522521

523-
status, err := cli.client.FuncStatus(context.Background(), name)
522+
status, err := cli.client.FuncStatus(context.Background(), cli.region, name)
524523
if err != nil {
525524
return err
526525
}

vendor/src/github.com/docker/engine-api/client/func.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"golang.org/x/net/context"
2121
)
2222

23-
func newFuncEndpointRequest(method, subpath string, query url.Values, body io.Reader) (*http.Request, error) {
23+
func newFuncEndpointRequest(region, method, subpath string, query url.Values, body io.Reader) (*http.Request, error) {
2424
endpoint := os.Getenv("HYPER_FUNC_ENDPOINT")
2525
if endpoint == "" {
26-
endpoint = "us-west-1.hyperfunc.io"
26+
endpoint = region + ".hyperfunc.io"
2727
}
2828
apiURL, err := url.Parse(endpoint)
2929
if err != nil {
@@ -182,7 +182,7 @@ func (cli *Client) FuncInspectWithCallId(ctx context.Context, id string) (*types
182182
return &fn, err
183183
}
184184

185-
func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader, sync bool) (io.ReadCloser, error) {
185+
func (cli *Client) FuncCall(ctx context.Context, region, name string, stdin io.Reader, sync bool) (io.ReadCloser, error) {
186186
fn, _, err := cli.FuncInspectWithRaw(ctx, name)
187187
if err != nil {
188188
return nil, err
@@ -191,7 +191,7 @@ func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader, s
191191
if sync {
192192
subpath += "/sync"
193193
}
194-
req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID, subpath), nil, stdin)
194+
req, err := newFuncEndpointRequest(region, "POST", path.Join("call", name, fn.UUID, subpath), nil, stdin)
195195
if err != nil {
196196
return nil, err
197197
}
@@ -202,7 +202,7 @@ func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader, s
202202
return resp.Body, nil
203203
}
204204

205-
func (cli *Client) FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error) {
205+
func (cli *Client) FuncGet(ctx context.Context, region, callId string, wait bool) (io.ReadCloser, error) {
206206
fn, err := cli.FuncInspectWithCallId(ctx, callId)
207207
if err != nil {
208208
return nil, err
@@ -211,7 +211,7 @@ func (cli *Client) FuncGet(ctx context.Context, callId string, wait bool) (io.Re
211211
if wait {
212212
subpath += "/wait"
213213
}
214-
req, err := newFuncEndpointRequest("GET", path.Join("output", fn.Name, fn.UUID, subpath), nil, nil)
214+
req, err := newFuncEndpointRequest(region, "GET", path.Join("output", fn.Name, fn.UUID, subpath), nil, nil)
215215
if err != nil {
216216
return nil, err
217217
}
@@ -222,7 +222,7 @@ func (cli *Client) FuncGet(ctx context.Context, callId string, wait bool) (io.Re
222222
return resp.Body, nil
223223
}
224224

225-
func (cli *Client) FuncLogs(ctx context.Context, name, callId string, follow bool, tail string) (io.ReadCloser, error) {
225+
func (cli *Client) FuncLogs(ctx context.Context, region, name, callId string, follow bool, tail string) (io.ReadCloser, error) {
226226
fn, _, err := cli.FuncInspectWithRaw(ctx, name)
227227
if err != nil {
228228
return nil, err
@@ -237,7 +237,7 @@ func (cli *Client) FuncLogs(ctx context.Context, name, callId string, follow boo
237237
if tail != "" {
238238
query.Add("tail", tail)
239239
}
240-
req, err := newFuncEndpointRequest("GET", path.Join("logs", name, fn.UUID, ""), query, nil)
240+
req, err := newFuncEndpointRequest(region, "GET", path.Join("logs", name, fn.UUID, ""), query, nil)
241241
if err != nil {
242242
return nil, err
243243
}
@@ -255,15 +255,15 @@ func (cli *Client) FuncLogs(ctx context.Context, name, callId string, follow boo
255255
return resp.Body, nil
256256
}
257257

258-
func (cli *Client) FuncStatus(ctx context.Context, name string) (*types.FuncStatusResponse, error) {
258+
func (cli *Client) FuncStatus(ctx context.Context, region, name string) (*types.FuncStatusResponse, error) {
259259
fn, _, err := cli.FuncInspectWithRaw(ctx, name)
260260
if err != nil {
261261
return nil, err
262262
}
263263

264264
query := url.Values{}
265265
query.Set("list", strconv.FormatBool(false))
266-
req, err := newFuncEndpointRequest("GET", path.Join("status", name, fn.UUID), query, nil)
266+
req, err := newFuncEndpointRequest(region, "GET", path.Join("status", name, fn.UUID), query, nil)
267267
if err != nil {
268268
return nil, err
269269
}

vendor/src/github.com/docker/engine-api/client/interface.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ type APIClient interface {
129129
FuncList(ctx context.Context, opts types.FuncListOptions) ([]types.Func, error)
130130
FuncInspect(ctx context.Context, name string) (types.Func, error)
131131
FuncInspectWithRaw(ctx context.Context, name string) (types.Func, []byte, error)
132-
FuncCall(ctx context.Context, name string, stdin io.Reader, sync bool) (io.ReadCloser, error)
133-
FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error)
134-
FuncLogs(ctx context.Context, name, callId string, follow bool, tail string) (io.ReadCloser, error)
135-
FuncStatus(ctx context.Context, name string) (*types.FuncStatusResponse, error)
132+
FuncCall(ctx context.Context, region, name string, stdin io.Reader, sync bool) (io.ReadCloser, error)
133+
FuncGet(ctx context.Context, region, callID string, wait bool) (io.ReadCloser, error)
134+
FuncLogs(ctx context.Context, region, name, callID string, follow bool, tail string) (io.ReadCloser, error)
135+
FuncStatus(ctx context.Context, region, name string) (*types.FuncStatusResponse, error)
136136
}
137137

138138
// Ensure that Client always implements APIClient.

0 commit comments

Comments
 (0)