Files
loki/vendor/github.com/go-openapi/validate/context.go
Jesus Vazquez db9dbe8e1d Bump prometheus dependency (#6403)
* Bump prometheus dependency

We had to add a replace of prometheus in go mod because thanos is
importing an older version and then replacing it.

* Undo textparser.New variable mismatch

* modtimevfs path update

* Fix labels withlabels and withoutlabels usages

WithoutLabels and WithLabels methods have dissappeared. Now
labels.NewBuilder has to be used.

* Fix RuleManager interface for Update()

Update now accepts a new param called ruleGroupPostProcessFunc which is
an optional function to be executed after rule group processing.

In this case I've set it to nil in the usages i've found.

* NewQueryRange now accepts QueryOpts

The NewQueryRange function now accepts QueryOptions so I had to update
all the calls.

I've set the opts to nil since we're not using them.

* gofmt
2022-06-15 12:16:23 -04:00

57 lines
1.4 KiB
Go

package validate
import (
"context"
)
// validateCtxKey is the key type of context key in this pkg
type validateCtxKey string
const (
operationTypeKey validateCtxKey = "operationTypeKey"
)
type operationType string
const (
request operationType = "request"
response operationType = "response"
none operationType = "none" // not specified in ctx
)
var operationTypeEnum = []operationType{request, response, none}
// WithOperationRequest returns a new context with operationType request
// in context value
func WithOperationRequest(ctx context.Context) context.Context {
return withOperation(ctx, request)
}
// WithOperationRequest returns a new context with operationType response
// in context value
func WithOperationResponse(ctx context.Context) context.Context {
return withOperation(ctx, response)
}
func withOperation(ctx context.Context, operation operationType) context.Context {
return context.WithValue(ctx, operationTypeKey, operation)
}
// extractOperationType extracts the operation type from ctx
// if not specified or of unknown value, return none operation type
func extractOperationType(ctx context.Context) operationType {
v := ctx.Value(operationTypeKey)
if v == nil {
return none
}
res, ok := v.(operationType)
if !ok {
return none
}
// validate the value is in operation enum
if err := Enum("", "", res, operationTypeEnum); err != nil {
return none
}
return res
}