// ContextWithRequestID returns ctx and the request ID if it already has one or creates and returns a new context with
// a new request ID.
484333
func ContextWithRequestID(ctx context.Context) (context.Context, string) {
	reqID := ContextRequestID(ctx)
	if reqID == "" {
		reqID = shortID()
		ctx = context.WithValue(ctx, reqIDKey, reqID)
	}
	return ctx, reqID
}
396189
func (o *GetIdentityIDParams) WithContext(ctx context.Context) *GetIdentityIDParams {
	o.SetContext(ctx)
	return o
}
1371494
func (o *RejectLogoutRequestParams) WithContext(ctx context.Context) *RejectLogoutRequestParams {
	o.SetContext(ctx)
	return o
}
820754
func GetRequestID(ctx context.Context) (uint64, bool) {
	var (
		szID   []string
		szIDOK bool
	)

	// Prefer the incoming context, but look in both types.
	if md, ok := metadata.FromIncomingContext(ctx); ok {
		szID, szIDOK = md[RequestIDKey]
	} else if md, ok := metadata.FromOutgoingContext(ctx); ok {
		szID, szIDOK = md[RequestIDKey]
	}

	if szIDOK && len(szID) == 1 {
		if id, err := strconv.ParseUint(szID[0], 10, 64); err == nil {
			return id, true
		}
	}

	return 0, false
}
739763
func (o *GetLogoutRequestParams) WithContext(ctx context.Context) *GetLogoutRequestParams {
	o.SetContext(ctx)
	return o
}
947501
func (o *CreateParams) WithContext(ctx context.Context) *CreateParams {
	o.SetContext(ctx)
	return o
}
917867
func (s *ServicesService) GetWithContext(ctx context.Context, idOrName string) (*Service, *http.Response, error) {
	resource, _ := url.Parse(servicesResourcePath)
	resource.Path = path.Join(resource.Path, idOrName)

	req, err := s.client.NewRequest(ctx, http.MethodGet, resource, nil)

	if err != nil {
		return nil, nil, err
	}

	svc := new(Service)

	res, err := s.client.Do(req, svc)

	if err != nil {
		return nil, res, err
	}

	return svc, res, nil
}
546670
func (o *CreateOAuth2ClientParams) WithContext(ctx context.Context) *CreateOAuth2ClientParams {
	o.SetContext(ctx)
	return o
}
446299
func (o *GetIdentityParams) WithContext(ctx context.Context) *GetIdentityParams {
	o.SetContext(ctx)
	return o
}
972060
func (o *PutEndpointIDParams) WithContext(ctx context.Context) *PutEndpointIDParams {
	o.SetContext(ctx)
	return o
}
1069828
func WithContext(ctx context.Context) func(*Client) error {
	return func(c *Client) error {
		c.Ctx = ctx
		return nil
	}
}
887701
func (q *Query) WithContext(ctx context.Context) *Query {
	q2 := *q
	q2.context = ctx
	return &q2
}
601077
func (r *Request) WithContext(ctx context.Context) *Request {
	if ctx == nil {
		panic("nil context")
	}
	r2 := r.copy()
	r2.ctx = ctx
	r2.cancelCtx = nil
	return r2
}
491303
func (client *Client) RequestWithContext(ctx context.Context, command Command) (interface{}, error) {
	switch c := command.(type) {
	case AsyncCommand:
		return client.asyncRequest(ctx, c)
	default:
		return client.SyncRequestWithContext(ctx, command)
	}
}
1018437
func GetRequestId(ctx context.Context) string {
	correlationId, _ := ctx.Value(RequestIdKey).(string)
	return correlationId
}
748400
func (o *GetEndpointIDHealthzParams) WithContext(ctx context.Context) *GetEndpointIDHealthzParams {
	o.SetContext(ctx)
	return o
}
314982
func RequestID(c context.Context) *fastjson.RawMessage {
	return c.Value(requestIDKey{}).(*fastjson.RawMessage)
}