-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(remote): embed log hook oplogs in hook context
I see hooks as part of a request/response lifecycle, which makes it appropriate to embed values in a context for later fetching. We're doing exactly that for oplogs, so hooks can get access to the logs being pushed without affecting the signature of a remote Hook, which is shared by datasets.
- Loading branch information
Showing
6 changed files
with
128 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package remote | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/qri-io/qri/logbook/oplog" | ||
) | ||
|
||
// The ctxKey type is unexported to prevent collisions with context keys defined | ||
// in other packages. | ||
type ctxKey int | ||
|
||
// oplogKey is the context key for an oplog.Log pointer. log hooks embed oplogs | ||
// in a context for access within a lifecycle hook | ||
const oplogKey ctxKey = 0 | ||
|
||
// newLogHookContext creates | ||
func newLogHookContext(ctx context.Context, l *oplog.Log) context.Context { | ||
return context.WithValue(ctx, oplogKey, l) | ||
} | ||
|
||
// OplogFromContext pulls an oplog value from | ||
func OplogFromContext(ctx context.Context) (l *oplog.Log, ok bool) { | ||
l, ok = ctx.Value(oplogKey).(*oplog.Log) | ||
return l, ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters