Skip to content

Commit

Permalink
feat(dispatch): Dispatch func can return 1-3 values, 2 being Cursor
Browse files Browse the repository at this point in the history
Func implementations registered with Dispatch can return 1-3 values.
Only 1 value means it must be an error. 2 values means the first is
any output and the second is an error. 3 values means the first is any
output, the second is a Cursor, and the third is an error. Cursor will
be used for pagination of methods that support it.
  • Loading branch information
dustmop committed Mar 5, 2021
1 parent c004812 commit 304f7c5
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 139 deletions.
18 changes: 9 additions & 9 deletions api/fsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (h *FSIHandlers) statusHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -102,7 +102,7 @@ func (h *FSIHandlers) whatChangedHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -141,7 +141,7 @@ func (h *FSIHandlers) initHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -180,7 +180,7 @@ func (h *FSIHandlers) canInitDatasetWorkDirHandler(routePrefix string) http.Hand
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -227,7 +227,7 @@ func (h *FSIHandlers) writeHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -274,7 +274,7 @@ func (h *FSIHandlers) createLinkHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -321,7 +321,7 @@ func (h *FSIHandlers) unlinkHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -368,7 +368,7 @@ func (h *FSIHandlers) checkoutHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down Expand Up @@ -415,7 +415,7 @@ func (h *FSIHandlers) restoreHandler(routePrefix string) http.HandlerFunc {
return
}

res, err := h.inst.Dispatch(r.Context(), method, p)
res, _, err := h.inst.Dispatch(r.Context(), method, p)
if err != nil {
util.RespondWithError(w, err)
return
Expand Down
3 changes: 1 addition & 2 deletions cmd/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func (o *CheckoutOptions) Run() (err error) {
return err
}

_, err = inst.Filesys().Checkout(ctx, &lib.LinkParams{Dir: o.Dir, Refstr: ref})
if err != nil {
if err = inst.Filesys().Checkout(ctx, &lib.LinkParams{Dir: o.Dir, Refstr: ref}); err != nil {
return err
}
printSuccess(o.Out, "created and linked working directory %s for existing dataset", o.Dir)
Expand Down
3 changes: 1 addition & 2 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func (o *RestoreOptions) Run() (err error) {
Component: o.ComponentName,
}

_, err = inst.Filesys().Restore(ctx, &params)
if err != nil {
if err = inst.Filesys().Restore(ctx, &params); err != nil {
return err
}
if o.ComponentName != "" && o.Path == "" {
Expand Down
2 changes: 1 addition & 1 deletion lib/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *CreateAuthTokenParams) Validate() error {
// private key for the grantee.
// Callers can provide either GranteeUsername OR GranteeProfileID
func (m AccessMethods) CreateAuthToken(ctx context.Context, p *CreateAuthTokenParams) (string, error) {
res, err := m.d.Dispatch(ctx, dispatchMethodName(m, "createauthtoken"), p)
res, _, err := m.d.Dispatch(ctx, dispatchMethodName(m, "createauthtoken"), p)
if s, ok := res.(string); ok {
return s, err
}
Expand Down
3 changes: 1 addition & 2 deletions lib/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,8 +1311,7 @@ func (m *DatasetMethods) Pull(ctx context.Context, p *PullParams) (*dataset.Data
Refstr: ref.Human(),
Dir: p.LinkDir,
}
fsiMethods := m.inst.Filesys()
if _, err = fsiMethods.Checkout(ctx, checkoutp); err != nil {
if err = m.inst.Filesys().Checkout(ctx, checkoutp); err != nil {
return nil, err
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/datasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func TestDatasetRequestsGetFSIPath(t *testing.T) {
Dir: dsDir,
Refstr: "peer/movies",
}
if _, err := fsim.Checkout(ctx, p); err != nil {
if err := fsim.Checkout(ctx, p); err != nil {
t.Fatalf("error checking out dataset: %s", err)
}

Expand Down Expand Up @@ -874,7 +874,7 @@ func TestDatasetRequestsRemove(t *testing.T) {
Dir: filepath.Join(datasetsDir, "cities"),
Refstr: "me/cities",
}
if _, err := fsim.Checkout(ctx, checkoutp); err != nil {
if err := fsim.Checkout(ctx, checkoutp); err != nil {
t.Fatal(err)
}

Expand All @@ -889,7 +889,7 @@ func TestDatasetRequestsRemove(t *testing.T) {
Dir: filepath.Join(datasetsDir, "craigslist"),
Refstr: "me/craigslist",
}
if _, err := fsim.Checkout(ctx, checkoutp); err != nil {
if err := fsim.Checkout(ctx, checkoutp); err != nil {
t.Fatal(err)
}

Expand Down
Loading

0 comments on commit 304f7c5

Please sign in to comment.