forked from TrueCloudLab/certificates
Add context methods for the acme linker.
This commit is contained in:
parent
bb8d85a201
commit
55b0f72821
1 changed files with 23 additions and 0 deletions
|
@ -41,6 +41,29 @@ type Linker interface {
|
||||||
LinkOrdersByAccountID(ctx context.Context, orders []string)
|
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.
|
// linker generates ACME links.
|
||||||
type linker struct {
|
type linker struct {
|
||||||
prefix string
|
prefix string
|
||||||
|
|
Loading…
Reference in a new issue