util

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

提供一些实用函数

Index

Constants

This section is empty.

Variables

View Source
var BeijingLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
View Source
var DefaultHttpClient *http.Client
View Source
var DefaultMediaHttpClient *http.Client

Functions

func Bool

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func Bool2Int

func Bool2Int(b bool) int

转换 bool 类型到 int 类型 true 转换为 1, false 转换为 0

func DecodeXMLToMap

func DecodeXMLToMap(r io.Reader) (m map[string]string, err error)

DecodeXMLToMap decodes xml reading from io.Reader and returns the first-level sub-node key-value set, if the first-level sub-node contains child nodes, skip it.

func EncodeXMLFromMap

func EncodeXMLFromMap(w io.Writer, m map[string]string, rootname string) (err error)

EncodeXMLFromMap encodes map[string]string to io.Writer with xml format.

NOTE: This function requires the rootname argument and the keys of m (type map[string]string) argument
are legitimate xml name string that does not contain the required escape character!

func Float32

func Float32(v float32) *float32

Float32 is a helper routine that allocates a new float32 value to store v and returns a pointer to it.

func Float64

func Float64(v float64) *float64

Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func HttpResponseWriter

func HttpResponseWriter(w io.Writer) http.ResponseWriter

将 io.Writer 从语义上实现 http.ResponseWriter.

func Int

func Int(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func Int32

func Int32(v int32) *int32

Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func NonceStr

func NonceStr() string

func Paginator0

func Paginator0(pageNum, currentPageIndex int) ([]int, error)

获取分页编号序列, 页码从 0 开始, 序列中非负整数表示页码, -1 表示省略, 如 [0,1,-1,8,9,10,11,12,-1,15,16] 表示 0,1,...,8,9,10,11,12,...,15,16

pageNum:          页面数量, 大于 0 的整数
currentPageIndex: 当前页码, 从 0 开始编码

func Paginator0Ex

func Paginator0Ex(totalItemNum, pageSize, currentPageIndex int) (arr []int, pageNum int, err error)

获取分页编号序列, 页码从 0 开始, 序列中非负整数表示页码, -1 表示省略, 如 [0,1,-1,8,9,10,11,12,-1,15,16] 表示 0,1,...,8,9,10,11,12,...,15,16

totalItemNum:     总的记录数量, 不是页面数量, 非负整数
pageSize:         每页显示的数量, 大于 0 的整数
currentPageIndex: 当前页码, 从 0 开始编码

func Paginator1

func Paginator1(pageNum, currentPageIndex int) (arr []int, err error)

获取分页编号序列, 页码从 1 开始, 序列中正整数表示页码, -1 表示省略, 如 [1,2,-1,8,9,10,11,12,-1,15,16] 表示 1,2,...,8,9,10,11,12,...,15,16

pageNum:          页面数量, 大于 0 的整数
currentPageIndex: 当前页码, 从 1 开始编码

func Paginator1Ex

func Paginator1Ex(totalItemNum, pageSize, currentPageIndex int) (arr []int, pageNum int, err error)

获取分页编号序列, 页码从 1 开始, 序列中正整数表示页码, -1 表示省略, 如 [1,2,-1,8,9,10,11,12,-1,15,16] 表示 1,2,...,8,9,10,11,12,...,15,16

totalItemNum:     总的记录数量, 不是页面数量, 非负整数
pageSize:         每页显示的数量, 大于 0 的整数
currentPageIndex: 当前页码, 从 1 开始编码

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func TrimSpace

func TrimSpace(src []byte) []byte

去掉 src 开头和结尾的空白, 如果 src 包括换行, 去掉换行和这个换行符两边的空白

NOTE: 根据 '\n' 来分行的, 某些系统或软件用 '\r' 来分行, 则不能正常工作.

func TrimSpaceString

func TrimSpaceString(src string) string

去掉 src 开头和结尾的空白, 如果 src 包括换行, 去掉换行和这个换行符两边的空白

NOTE: 根据 '\n' 来分行的, 某些系统或软件用 '\r' 来分行, 则不能正常工作.

func Uint32

func Uint32(v uint32) *uint32

Uint32 is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.

func Uint64

func Uint64(v uint64) *uint64

Uint64 is a helper routine that allocates a new uint64 value to store v and returns a pointer to it.

func WXVersion

func WXVersion(userAgent string) (x, y, z, w int, err error)

获取微信客户端的版本.

userAgent: 微信内置浏览器的 User-Agent;
x, y, z, w:   如果微信版本为 5.3.1.2 则有 x==5, y==3, z==1, w==2
err:       错误信息

Types

type RoundRobinIndex

type RoundRobinIndex struct {
	// contains filtered or unexported fields
}

func NewRoundRobinIndex

func NewRoundRobinIndex(bound int) *RoundRobinIndex

func (*RoundRobinIndex) Next

func (rr *RoundRobinIndex) Next() int

Directories

Path Synopsis
提供一些常用的检查, 如检查一个字符串是否符合 email 格式.
提供一些常用的检查, 如检查一个字符串是否符合 email 格式.
提供常用的 html/template 函数
提供常用的 html/template 函数

Jump to

Keyboard shortcuts

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