mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
a3d3fe727d
* Made custom and random UA optional * Added pirvate context keys
32 lines
460 B
Go
32 lines
460 B
Go
package env
|
|
|
|
import "context"
|
|
|
|
type (
|
|
ctxKey struct{}
|
|
|
|
Environment struct {
|
|
CDPAddress string
|
|
ProxyAddress string
|
|
UserAgent string
|
|
}
|
|
)
|
|
|
|
const RandomUserAgent = "*"
|
|
|
|
func WithContext(ctx context.Context, e Environment) context.Context {
|
|
return context.WithValue(ctx, ctxKey{}, e)
|
|
}
|
|
|
|
func FromContext(ctx context.Context) Environment {
|
|
res := ctx.Value(ctxKey{})
|
|
|
|
val, ok := res.(Environment)
|
|
|
|
if !ok {
|
|
return Environment{}
|
|
}
|
|
|
|
return val
|
|
}
|