设为首页 加入收藏

TOP

[自翻]fasthttp中文文档(持续更新)(五)
2017-09-30 13:50:09 】 浏览:3078
Tags:自翻 fasthttp 中文 文档 持续 更新
讯参数值。

返回值在下一次调用Args前有效。

func (a *Args) PeekBytes(key []byte) []byte
PeekBytes函数用于返回给定键key的查询参数值。
返回值在下一次调用Args前有效。

func (a *Args) PeekMulti(key string) [][]byte
PeekMulti函数用于返回给定键key的所有参数值。

func (a *Args) PeekMultiBytes(key []byte) [][]byte
PeekMultiBytes函数用于返回给定键key的所有参数值。

func (a *Args) QueryString() []byte
QueryString函数用于返回args的查询字符串。
返回值在下一次调用Args方法前有效。

func (a *Args) Reset()
Reset函数用于情况查询参数args。

func (a *Args) Set(key, value string)
Set函数用于设置“key=value”键值对参数。

func (a *Args) SetBytesK(key []byte, value string)
SetBytesK函数用于设置“key=value”键值对参数。

func (a *Args) SetBytesKV(key, value []byte)
SetBytesKV函数用于设置“key=value”键值对参数。

func (a *Args) SetBytesV(key string, value []byte)
SetBytesV函数用于设置“key=value”键值对参数。

func (a *Args) SetUint(key string, value int)
SetUint函数通过给定键key设置无符号整数值。

func (a *Args) SetUintBytes(key []byte, value int)
SetUintBytes函数通过给定键key设置无符号整数值。

func (a *Args) String() string
String函数用于返回查询参数args的字符串表示。

func (a *Args) VisitAll(f func(key, value []byte))
VisitAll函数会对于每一个存在的arg参数调用函数f。
f函数不得在返回后保留键、值的引用。如果你需要在返回后存储他们,请创建键、值的副本。

func (a *Args) WriteTo(w io.Writer) (int64, error)
WriteTo函数用于吸入查询字符串到写入器w中。
WriteTo实现了io.WriteTo接口。

type BalancingClient

type BalancingClient interface {
DoDeadline(req *Request, resp *Response, deadline time.Time) error
PendingRequests() int
}

BalancingClient是一个客户端接口,其可被传递给LBClient.Client。

type ByteBuffer

type ByteBuffer bytebufferpool.ByteBuffer

ByteBuffer提供字节缓冲器,其可以于fasthttp API中以减少内存分配。
使用AcquireByteBuffer可获得一个空的字节缓冲器。
不推荐使用ByteBuffer。请使用 github.com/valyala/bytebufferpool 替代。
例程:

// 该请求handler用于设置“Your-IP”你的IP响应头
// “Your IP is <ip>”信息利用ByteBuffer构建响应。
// header将分配为零值。
yourIPRequestHandler := func(ctx *fasthttp.RequestCtx) {
    b := fasthttp.AcquireByteBuffer()
    b.B = append(b.B, "Your IP is <"...)
    b.B = fasthttp.AppendIPv4(b.B, ctx.RemoteIP())
    b.B = append(b.B, ">"...)
    ctx.Response.Header.SetBytesV("Your-IP", b.B)

    fmt.Fprintf(ctx, "Check response headers - they must contain 'Your-IP: %s'", b.B)

    // 现在便可以安全地释放字节缓冲器了。
    // 不再使用。
    fasthttp.ReleaseByteBuffer(b)
}

// 启动fasthttp服务,并在响应头中返回你的IP。
fasthttp.ListenAndServe(":8080", yourIPRequestHandler)

func AcquireByteBuffer() *ByteBuffer
AcquireByteBuffer用于从池中返回一个空的字节缓冲器。
获取字节缓冲器可能会通过调用ReleaseByteBuffer函数而被返回到池中。这会减少字节缓冲器管理所需的内存分配数量。

func (b *ByteBuffer) Reset()
Reset函数用于清空字节缓冲器ByteBuffer.B。

func (b *ByteBuffer) Set(p []byte)
Set函数用于设置字节缓冲器ByteBuffer.B至字节切片p中。

func (b *ByteBuffer) SetString(s string)
SetString函数用于设置字节缓冲器ByteBuffer.B至字符串s中。

func (b *ByteBuffer) Write(p []byte) (int, error)
Write函数用于实现io.Writer写入器,其用于附加字节切片p至字节缓冲器ByteBuffer.B中。

func (b *ByteBuffer) WriteString(s string) (int, error)
WriteString函数用于附加字符串s至字节缓冲器ByteBuffer.B中。

type Client

type Client struct {

    // 客户端名称。用于请求头User-Agent中。
    //
    // 如果未设置,将使用默认客户端名称。
    Name string

    // 通过回调建立到主机的新连接。
    //
    // 如果未设置,将使用默认的Dial函数。
    Dial DialFunc

    // 若设置为true,会尝试连接到IPv4和IPv6地址。
    //
    // 仅当默认TCP dialer被使用时,此选项被使用,即Dial为空白时。
    //
    // 由于在很多地方IPv6网络仍未普及,默认情况下客户端只连接到IPv4地址。
    //
    DialDualStack bool

    // 用于https连接的TLS配置。
    //
    // 若未设置,将使用默认TLS配置。
    TLSConfig *tls.Config

    // 在每个主机上可能被建立的最大连接数。
    //
    // 若未设置,将使用DefaultMaxConnsPerHos
首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇用go和zk实现一个简单的分布式ser.. 下一篇Mac上安装go环境

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目