emissary/internal/agent/context.go

28 lines
529 B
Go
Raw Normal View History

package agent
import (
"context"
2023-06-25 19:45:43 +02:00
"forge.cadoles.com/Cadoles/emissary/pkg/client"
"github.com/pkg/errors"
)
type contextKey string
const (
contextKeyClient contextKey = "client"
)
func withClient(ctx context.Context, client *client.Client) context.Context {
return context.WithValue(ctx, contextKeyClient, client)
}
func Client(ctx context.Context) *client.Client {
client, ok := ctx.Value(contextKeyClient).(*client.Client)
if !ok {
panic(errors.New("could not retrieve client from context"))
}
return client
}