// RequestOptions returns an Opt that applies the given set of options to every Client request.
506647
func RequestOptions(opts ...RequestOpt) Opt {
	if len(opts) == 0 {
		return nil
	}
	return func(c *Client) Opt {
		old := append([]RequestOpt{}, c.requestOpts...)
		c.requestOpts = opts
		return RequestOptions(old...)
	}
}
626581
func (q *Query) Options() *QueryOptions {
	options := NewQueryOptions()
	queryParams, _ := ParseQuery(q.Query)
	for _, queryParam := range queryParams.All() {
		param, modifier, _ := ParseParamNameModifierAndPostFix(queryParam.Key)
		if !strings.HasPrefix(param, "_") || isGlobalSearchParam(param) {
			continue
		}

		switch param {

		case CountParam:
			count, err := strconv.Atoi(queryParam.Value)
			if err != nil {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_count\" content is invalid"))
			}
			if count >= 0 {
				options.Count = count
			}

		case OffsetParam:
			offset, err := strconv.Atoi(queryParam.Value)
			if err != nil {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_offset\" content is invalid"))
			}
			if offset >= 0 {
				options.Offset = offset
			}

		case SortParam:
			// The following supports both DSTU2-style sorts and STU3-style sorts
			keys := strings.Split(queryParam.Value, ",")
			for _, key := range keys {
				desc := strings.HasPrefix(key, "-") || modifier == "desc"
				sortParam, ok := SearchParameterDictionary[q.Resource][strings.TrimPrefix(key, "-")]
				if !ok {
					panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_sort\" content is invalid"))
				}
				options.Sort = append(options.Sort, SortOption{Descending: desc, Parameter: sortParam})
			}
			// If this was an STU3-style sort, remember that so we reconstruct the query URL correctly
			if len(keys) > 1 || strings.HasPrefix(queryParam.Value, "-") {
				options.IsSTU3Sort = true
			}

		case IncludeParam:
			incls := strings.Split(queryParam.Value, ":")
			if len(incls) < 2 || len(incls) > 3 {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_include\" content is invalid"))
			}
			inclParam, ok := SearchParameterDictionary[incls[0]][incls[1]]
			if !ok {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_include\" content is invalid"))
			}
			// Only reference paramaters count, so verify it is a reference parameter
			if inclParam.Type != "reference" {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_include\" content is invalid"))
			}
			if len(incls) == 3 {
				if isValidTarget(incls[2], inclParam) {
					// Modify the targets to include only the one noted
					inclParam.Targets = []string{incls[2]}
				} else {
					panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_include\" content is invalid"))
				}
			}
			options.Include = append(options.Include, IncludeOption{Resource: incls[0], Parameter: inclParam})

		case RevIncludeParam:
			incls := strings.Split(queryParam.Value, ":")
			if len(incls) < 2 || len(incls) > 3 {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_revinclude\" content is invalid"))
			}
			revInclParam, ok := SearchParameterDictionary[incls[0]][incls[1]]
			if !ok {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_revinclude\" content is invalid"))
			}
			// Only reference paramaters count, so verify it is a reference parameter
			if revInclParam.Type != "reference" {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_revinclude\" content is invalid"))
			}
			// Only the currently searched on resource is a valid target (or "Any")
			target := q.Resource
			if len(incls) == 3 && incls[2] != target && incls[2] != "Any" {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_revinclude\" content is invalid"))
			}
			// Make sure the selected param actually supports the intended target
			if isValidTarget(target, revInclParam) {
				// Modify the targets to include only the resource we're searching on
				revInclParam.Targets = []string{target}
			} else {
				panic(createInvalidSearchError("MSG_PARAM_INVALID", "Parameter \"_revinclude\" content is invalid"))
			}
			options.RevInclude = append(options.RevInclude, RevIncludeOption{Resource: incls[0], Parameter: revInclParam})

		case FormatParam:
			if queryParam.Value != "json" && queryParam.Value != "application/json" && queryParam.Value != "application/json+fhir" {
				// Currently we only support JSON
				panic(createUnsupportedSearchError("MSG_PARAM_INVALID", "Parameter \"_format\" content is invalid"))
			}

		default:
			panic(createUnsupportedSearchError("MSG_PARAM_UNKNOWN", fmt.Sprintf("Parameter \"%s\" not understood", param)))
		}
	}
	return options
}
1257151
func (g *Group) Options(path string, h HandlerFunc, opts ...HandlerOption) {
	g.add(path, h, opts, http.MethodOptions)
}
498755
func RequestTimeout(d time.Duration) Option {
	return func(o *Options) {
		o.CallOptions.RequestTimeout = d
	}
}
1160135
func ClientOption(c ...option.ClientOption) broker.Option {
	return func(o *broker.Options) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, clientOptionKey{}, c)
	}
}
2547
func addOptions(s string, opt interface{}) (string, error) {
	v := reflect.ValueOf(opt)
	if v.Kind() == reflect.Ptr && v.IsNil() {
		return s, nil
	}

	u, err := url.Parse(s)
	if err != nil {
		return s, err
	}

	qs, err := query.Values(opt)
	if err != nil {
		return s, err
	}

	u.RawQuery = qs.Encode()
	return u.String(), nil
}
287185
func (c *ExtensionManagerClient) Options() (osquery.InternalOptionList, error) {
	return c.Client.Options(context.Background())
}
1183799
func (c *Client) prepareRequestOpts(options ...RequestOption) (requestOptions, error) {
	opts := requestOptions{}
	for _, option := range options {
		err := option(c.ctx, &opts)
		if err != nil {
			return opts, errors.WithMessage(err, "Failed to read request opts")
		}
	}

	// Set defaults for max targets
	if opts.MaxTargets == 0 {
		opts.MaxTargets = maxTargets
	}

	// Set defaults for min targets/matches
	if opts.MinTargets == 0 {
		opts.MinTargets = minTargets
	}

	if opts.MinTargets > opts.MaxTargets {
		opts.MaxTargets = opts.MinTargets
	}

	return opts, nil
}
515248
func (h *Client) Option(opts ...Option) *Client {
	for _, opt := range opts {
		opt(&h.opts)
	}
	return h
}
1129920
func (c *Client) prepareOptsFromOptions(ctx context.Client, options ...RequestOption) (requestOptions, error) {
	opts := requestOptions{}
	for _, option := range options {
		err := option(ctx, &opts)
		if err != nil {
			return opts, errors.WithMessage(err, "Failed to read opts")
		}
	}
	return opts, nil
}
1078470
func (s *CertificateDetail) SetOptions(v *CertificateOptions) *CertificateDetail {
	s.Options = v
	return s
}
953811
func (r *Request) QueryOption(key string, value string) *Request {
	if r.err != nil {
		return r
	}
	if r.params == nil {
		r.params = make(url.Values)
	}
	r.params.Add(string(key), value)
	return r
}
1243788
func (r *Router) Options(path string, fn interface{}) *Router {
	return r.addRoute(httpMethodOptions, path, fn)
}
729641
func Options(opts ...grpc.ServerOption) server.Option {
	return func(o *server.Options) {
		if o.Context == nil {
			o.Context = context.Background()
		}
		o.Context = context.WithValue(o.Context, grpcOptions{}, opts)
	}
}
578285
func (r *Route) Options(handler http.Handler) *Route {
	r.handlers[http.MethodOptions] = handler
	return r
}
317789
func (c *Endpoint) ClientOpts() ([]client.Opt, error) {
	var result []client.Opt
	if c.Host != "" {
		helper, err := connhelper.GetConnectionHelper(c.Host)
		if err != nil {
			return nil, err
		}
		if helper == nil {
			tlsConfig, err := c.tlsConfig()
			if err != nil {
				return nil, err
			}
			result = append(result,
				client.WithHost(c.Host),
				withHTTPClient(tlsConfig),
			)

		} else {
			httpClient := &http.Client{
				// No tls
				// No proxy
				Transport: &http.Transport{
					DialContext: helper.Dialer,
				},
			}
			result = append(result,
				client.WithHTTPClient(httpClient),
				client.WithHost(helper.Host),
				client.WithDialContext(helper.Dialer),
			)
		}
	}

	version := os.Getenv("DOCKER_API_VERSION")
	if version != "" {
		result = append(result, client.WithVersion(version))
	}
	return result, nil
}
33236
func (i *Index) Options() IndexOptions {
	i.mu.RLock()
	defer i.mu.RUnlock()
	return i.options()
}