mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-22 17:42:14 +08:00
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
// Copyright 2018 Gin Core Team. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package internal
|
|
|
|
// Param is a single URL parameter, consisting of a key and a value.
|
|
type Param struct {
|
|
Key string
|
|
Value string
|
|
}
|
|
|
|
// Params is a Param-slice, as returned by the router.
|
|
// The slice is ordered, the first URL parameter is also the first slice value.
|
|
// It is therefore safe to read values by the index.
|
|
type Params []Param
|
|
|
|
// Get returns the value of the first Param which key matches the given name.
|
|
// If no matching Param is found, an empty string is returned.
|
|
func (ps Params) Get(name string) (string, bool) {
|
|
for _, entry := range ps {
|
|
if entry.Key == name {
|
|
return entry.Value, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
// ByName returns the value of the first Param which key matches the given name.
|
|
// If no matching Param is found, an empty string is returned.
|
|
func (ps Params) ByName(name string) (va string) {
|
|
va, _ = ps.Get(name)
|
|
return
|
|
}
|