// PathParam matches if a given path parameter key is present in the URL.
//
// The value is representative of the restful resource the key defines, e.g.
//   // /users/123/name
//   r.PathParam("users", "123")
// would match.
172128
func (r *Request) PathParam(key, val string) *Request {
	r.PathParams[key] = val

	return r
}
1124024
func (r *Router) GetParams(method, path string) (httprouter.Params, bool) {
	if h, p, _ := r.hrouter.Lookup(method, path); h != nil {
		return p, true
	}
	return nil, false
}
3041
func Param(key, value string) p.Plugin {
	return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
		ctx.Request.URL.Path = replace(ctx.Request.URL.Path, key, value)
		h.Next(ctx)
	})
}
1044045
func URLQueryParam(in string) string {
	var out = &bytes.Buffer{}
	var c byte
	for i := 0; i < len(in); i++ {
		c = in[i]
		if (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 45 || c == 46 || c == 126 || c == 95 {
			// a-zA-Z0-9-._~
			out.WriteByte(c)
		} else {
			// UTF-8
			fmt.Fprintf(out, "%%%02X", c)
		}
	}
	return out.String()
}
156107
func (b binding) hasEnumPathParam(repeated bool) bool {
	for _, p := range b.PathParams {
		if p.IsEnum() && p.IsRepeated() == repeated {
			return true
		}
	}
	return false
}
550284
func (p *Parameter) findParam(idx int) (string, error) {
	index := len(p.names) - 1
	urlPath := p.path
	pathLen := len(p.path)
	node := p.node

	for node != nil {
		if node.text[0] == ':' {
			ctn := lastIndexByte(urlPath, '/')
			if ctn == -1 {
				return "", fmt.Errorf("Parameter not found")
			}
			pathLen = ctn + 1
			if index == idx {
				return urlPath[pathLen:], nil
			}
			index--
		} else {
			pathLen -= len(node.text)
		}
		urlPath = urlPath[0:pathLen]
		node = node.parent
	}
	return "", fmt.Errorf("Parameter not found")
}
1334420
func pathParams(r *design.RouteDefinition) string {
	pnames := r.Params()
	params := make(design.Object, len(pnames))
	for _, p := range pnames {
		params[p] = r.Parent.Params.Type.ToObject()[p]
	}
	return join(&design.AttributeDefinition{Type: params}, false, pnames)
}
604241
func buildURLParams(userURL string, params map[string]string) (string, error) {
	parsedURL, err := url.Parse(userURL)

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

	parsedQuery, err := url.ParseQuery(parsedURL.RawQuery)

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

	for key, value := range params {
		parsedQuery.Set(key, value)
	}

	return addQueryParams(parsedURL, parsedQuery), nil
}
1101300
func (v *evalVisitor) findBlockParam(node *ast.PathExpression) (string, interface{}) {
	if len(node.Parts) > 0 {
		name := node.Parts[0]
		if value := v.blockParam(name); value != nil {
			return name, value
		}
	}

	return "", nil
}
653117
func (m *RouteMux) FilterParam(param string, filter http.HandlerFunc) {
	if !strings.HasPrefix(param,":") {
		param = ":"+param
	}

	m.Filter(func(w http.ResponseWriter, r *http.Request) {
		p := r.URL.Query().Get(param)
		if len(p) > 0 { filter(w, r) }
	})
}
627228
func pathMatch(pattern, path string) bool {
	if len(pattern) == 0 {
		// should not happen
		return false
	}
	n := len(pattern)
	if pattern[n-1] != '/' {
		return pattern == path
	}
	return len(path) >= n && path[0:n] == pattern
}
261282
func (b *HttpRequest) Param(key, value string) *HttpRequest {
	b.params[key] = value
	return b
}
943998
func Param(i interface{}) string {
	switch v := i.(type) {
	case string:
		return v
	case []string:
		return strings.Join(v, ",")
	case int:
		return strconv.Itoa(v)
	case []int:
		return slices.Ints(v).Join("", ",")
	case uint:
		return strconv.FormatUint(uint64(v), 10)
	case []uint:
		return slices.Uints(v).Join("", ",")
	case []byte:
		return string(v)
	}

	panic("Only support int, []int, uint, []uint, string, []string, []byte")
}
792958
func (r *ResponseMatcher) Path(p string) *ResponseMatcher {
	r.mux.mu.Lock()
	defer r.mux.mu.Unlock()
	r.path = p
	return r
}
1025526
func PathParameter(name, description string) *Parameter {
	p := &Parameter{&ParameterData{Name: name, Description: description, Required: true, DataType: "string"}}
	p.bePath()
	return p
}
1133495
func Param(r *http.Request, key string) string {
	p := Params(r)
	if v, ok := p[key]; ok {
		return v
	}
	return ""
}
597017
func (this *Server) Param(p string, fn func(*Request, *Response, func())) {
	this.Router.AddParamFunc(p, fn)
}