emissary/internal/agent/context.go
William Petit 42d49eb090
All checks were successful
arcad/emissary/pipeline/head This commit looks good
feat: move client to public package
2023-06-25 11:46:33 -06:00

28 lines
529 B
Go

package agent
import (
"context"
"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
}