Files
Gardomatic/lib/client/context.go
T
kleiax 904d14b64c
CI / test (push) Canceled after 0s
Initial commit
2026-09-12 22:22:17 +02:00

17 lines
441 B
Go

package client
import "context"
type contextKey struct{}
// NewContext attaches an API client to a context.
func NewContext(ctx context.Context, apiClient *Client) context.Context {
return context.WithValue(ctx, contextKey{}, apiClient)
}
// FromContext returns the API client attached to ctx, or nil if none exists.
func FromContext(ctx context.Context) *Client {
apiClient, _ := ctx.Value(contextKey{}).(*Client)
return apiClient
}