params

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2018 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

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

Index

Constants

View Source
const ContextKeyParams contextKey = 0

ContextKeyParams 存取路由参数的关键字

Variables

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

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

Functions

This section is empty.

Types

type Params

type Params map[string]string

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

func Get

func Get(r *http.Request) Params

Get 获得一个 Params 实例。

以下情况两个参数都会返回 nil:

非正则和命名路由;
正则路由,但是所有匹配参数都是未命名的;

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 查找指定名称的参数是否存在。 可选参数,可能会不存在。

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