Ai
1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
context.go 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
Cyril Cressent 提交于 2018-11-24 02:19 +08:00 . Complete redesign of RBAC (#2338)
package testutil
import (
"context"
"github.com/coreos/etcd/store"
"github.com/sensu/sensu-go/types"
)
// SetContextFn take context and return new context
type SetContextFn func(context.Context) context.Context
// NewContext instantiates new todo context and applies given contextFns to it.
func NewContext(fns ...SetContextFn) (ctx context.Context) {
ctx = context.TODO()
ctx = ApplyContext(ctx, fns...)
return
}
// ApplyContext applies given contextFns to context.
func ApplyContext(ctx context.Context, fns ...SetContextFn) context.Context {
for _, fn := range fns {
ctx = fn(ctx)
}
return ctx
}
// ContextWithNamespace returns new contextFn with namespace added.
func ContextWithNamespace(namespace string) SetContextFn {
return func(ctx context.Context) context.Context {
ctx = context.WithValue(ctx, types.NamespaceKey, namespace)
return ctx
}
}
// ContextWithStore returns new contextFn with given store value applied to
// context.
func ContextWithStore(store store.Store) SetContextFn {
return func(ctx context.Context) context.Context {
return context.WithValue(ctx, types.StoreKey, store)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助