mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
25 lines
578 B
Go
25 lines
578 B
Go
// Package host enables setting and reading
|
|
// the current host from context
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/fleetdm/fleet/server/kolide"
|
|
)
|
|
|
|
type key int
|
|
|
|
const hostKey key = 0
|
|
|
|
// NewContext returns a new context carrying the current osquery host.
|
|
func NewContext(ctx context.Context, host kolide.Host) context.Context {
|
|
return context.WithValue(ctx, hostKey, host)
|
|
}
|
|
|
|
// FromContext extracts the osquery host from context if present.
|
|
func FromContext(ctx context.Context) (kolide.Host, bool) {
|
|
host, ok := ctx.Value(hostKey).(kolide.Host)
|
|
return host, ok
|
|
}
|