mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-05 18:40:59 +00:00
27 lines
545 B
Go
27 lines
545 B
Go
|
// Copyright 2025 The Forgejo Authors
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
package common
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
)
|
||
|
|
||
|
type daemonContextKey string
|
||
|
|
||
|
const daemonContextKeyVal = daemonContextKey("daemon")
|
||
|
|
||
|
func DaemonContext(ctx context.Context) context.Context {
|
||
|
val := ctx.Value(daemonContextKeyVal)
|
||
|
if val != nil {
|
||
|
if daemon, ok := val.(context.Context); ok {
|
||
|
return daemon
|
||
|
}
|
||
|
}
|
||
|
return context.Background()
|
||
|
}
|
||
|
|
||
|
func WithDaemonContext(ctx, daemon context.Context) context.Context {
|
||
|
return context.WithValue(ctx, daemonContextKeyVal, daemon)
|
||
|
}
|