mirror of
https://github.com/onyx-and-iris/exclude.git
synced 2026-03-30 23:19:09 +00:00
22 lines
512 B
Go
22 lines
512 B
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
)
|
|
|
|
type contextKey string
|
|
|
|
const fileContextKey contextKey = "excludeFile"
|
|
|
|
// ContextWithFile returns a new context with the given file set.
|
|
func ContextWithFile(ctx context.Context, file *os.File) context.Context {
|
|
return context.WithValue(ctx, fileContextKey, file)
|
|
}
|
|
|
|
// FileFromContext retrieves the file from the context, if it exists.
|
|
func FileFromContext(ctx context.Context) (*os.File, bool) {
|
|
file, ok := ctx.Value(fileContextKey).(*os.File)
|
|
return file, ok
|
|
}
|