params

package
v5.0.0-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package params 获取和转换路由中的参数信息

Index

Constants

This section is empty.

Variables

View Source
var ErrParamNotExists = errors.New("不存在该参数")

ErrParamNotExists 表示地址参数中并不存在该名称的值

Functions

func WithValue

func WithValue(r *http.Request, ps Params) *http.Request

WithValue 将参数 ps 附加在 r 上

与 context.WithValue 功能相同,但是考虑了在同一个 r 上调用多次 WithValue 的情况。

Types

type Params

type Params map[string]string

Params 获取和转换路由中的参数信息

func Get

func Get(r *http.Request) Params

Get 获取当前请求实例上的参数列表

func (Params) Bool

func (p Params) Bool(key string) (bool, error)

Bool 获取地址参数中的名为 key 的变量并将其转换成 bool

当参数不存在时,返回 ErrParamNotExists 错误。

func (Params) Exists

func (p Params) Exists(key string) bool

Exists 查找指定名称的参数是否存在

NOTE: 如果是可选参数,可能会不存在。

func (Params) Float

func (p Params) Float(key string) (float64, error)

Float 获取地址参数中的名为 key 的变量并将其转换成 Float64

当参数不存在时,返回 ErrParamNotExists 错误。

func (Params) Int

func (p Params) Int(key string) (int64, error)

Int 获取地址参数中的名为 key 的变量并将其转换成 int64

当参数不存在时,返回 ErrParamNotExists 错误。

func (Params) MustBool

func (p Params) MustBool(key string, def bool) bool

MustBool 获取地址参数中的名为 key 的变量并将其转换成 bool

若不存在或是无法转换则返回 def。

func (Params) MustFloat

func (p Params) MustFloat(key string, def float64) float64

MustFloat 获取地址参数中的名为 key 的变量并将其转换成 float64

若不存在或是无法转换则返回 def。

func (Params) MustInt

func (p Params) MustInt(key string, def int64) int64

MustInt 获取地址参数中的名为 key 的变量并将其转换成 int64

若不存在或是无法转换则返回 def。

func (Params) MustString

func (p Params) MustString(key, def string) string

MustString 获取地址参数中的名为 key 的变量并将其转换成 string

若不存在或是无法转换则返回 def。

func (Params) MustUint

func (p Params) MustUint(key string, def uint64) uint64

MustUint 获取地址参数中的名为 key 的变量并将其转换成 uint64

若不存在或是无法转换则返回 def。

func (Params) String

func (p Params) String(key string) (string, error)

String 获取地址参数中的名为 key 的变量并将其转换成 string

当参数不存在时,返回 ErrParamNotExists 错误。

func (Params) Uint

func (p Params) Uint(key string) (uint64, error)

Uint 获取地址参数中的名为 key 的变量并将其转换成 uint64

当参数不存在时,返回 ErrParamNotExists 错误。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL