예제 #1
0
파일: context.go 프로젝트: rht/bssim
// ContextWithLoggable returns a derived context which contains the provided
// Loggable. Any Events logged with the derived context will include the
// provided Loggable.
func ContextWithLoggable(ctx context.Context, l Loggable) context.Context {
	existing, err := MetadataFromContext(ctx)
	if err != nil {
		// context does not contain meta. just set the new metadata
		child := context.WithValue(ctx, metadataKey, Metadata(l.Loggable()))
		return child
	}

	merged := DeepMerge(existing, l.Loggable())
	child := context.WithValue(ctx, metadataKey, merged)
	return child
}
예제 #2
0
파일: query.go 프로젝트: rht/bssim
func RegisterForQueryEvents(ctx context.Context, ch chan<- *QueryEvent) context.Context {
	return context.WithValue(ctx, RoutingQueryKey, ch)
}
예제 #3
0
파일: context.go 프로젝트: rht/bssim
// ContextWithErrorLog returns a copy of parent and an error channel that can
// be used to receive errors sent with the LogError method.
func ContextWithErrorLog(parent context.Context) (context.Context, <-chan error) {
	errs := make(privateChanType)
	ctx := context.WithValue(parent, errLogKey, errs)
	return ctx, errs
}