add a function to set request source task type (#925)

* add a function to set request source task type

Signed-off-by: glorv <glorvs@163.com>
This commit is contained in:
glorv 2023-08-09 13:03:15 +08:00 committed by GitHub
parent a0d916d116
commit 300545a8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -48,10 +48,11 @@ const (
ExplicitTypeBR = "br"
ExplicitTypeDumpling = "dumpling"
ExplicitTypeBackground = "background"
ExplicitTypeDDL = "ddl"
)
// ExplicitTypeList is the list of all explicit source types.
var ExplicitTypeList = []string{ExplicitTypeEmpty, ExplicitTypeLightning, ExplicitTypeBR, ExplicitTypeDumpling, ExplicitTypeBackground}
var ExplicitTypeList = []string{ExplicitTypeEmpty, ExplicitTypeLightning, ExplicitTypeBR, ExplicitTypeDumpling, ExplicitTypeBackground, ExplicitTypeDDL}
const (
// InternalRequest is the scope of internal queries
@ -94,6 +95,15 @@ func WithInternalSourceType(ctx context.Context, source string) context.Context
})
}
// WithInternalSourceAndTaskType create context with internal source and task name.
func WithInternalSourceAndTaskType(ctx context.Context, source, taskName string) context.Context {
return context.WithValue(ctx, RequestSourceKey, RequestSource{
RequestSourceInternal: true,
RequestSourceType: source,
ExplicitRequestSourceType: taskName,
})
}
// BuildRequestSource builds a request_source from internal, source and explicitSource.
func BuildRequestSource(internal bool, source, explicitSource string) string {
requestSource := RequestSource{