|
|
@@ -41,6 +41,29 @@ type Linker interface {
|
|
|
LinkOrdersByAccountID(ctx context.Context, orders []string)
|
|
|
}
|
|
|
|
|
|
+type linkerKey struct{}
|
|
|
+
|
|
|
+// NewLinkerContext adds the given linker to the context.
|
|
|
+func NewLinkerContext(ctx context.Context, v Linker) context.Context {
|
|
|
+ return context.WithValue(ctx, linkerKey{}, v)
|
|
|
+}
|
|
|
+
|
|
|
+// LinkerFromContext returns the current linker from the given context.
|
|
|
+func LinkerFromContext(ctx context.Context) (v Linker, ok bool) {
|
|
|
+ v, ok = ctx.Value(linkerKey{}).(Linker)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// MustLinkerFromContext returns the current linker from the given context. It
|
|
|
+// will panic if it's not in the context.
|
|
|
+func MustLinkerFromContext(ctx context.Context) Linker {
|
|
|
+ if v, ok := LinkerFromContext(ctx); !ok {
|
|
|
+ panic("acme linker is not the context")
|
|
|
+ } else {
|
|
|
+ return v
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// linker generates ACME links.
|
|
|
type linker struct {
|
|
|
prefix string
|