Back to

Package util

Latest Go to latest

The latest major version is .

Published: Sep 20, 2020 | License: BSD-3-Clause | Module:


Package utf8string provides an efficient way to index strings by rune rather than by byte.



const CaptchaLen = 4
const XRequestedWith = "X-Requested-With"

func CheckInt

func CheckInt(form url.Values, field string) bool

检测提交请求的参数是否是 int 类型

func DoGet

func DoGet(url string, extras (body []byte, err error)

func DoPost

func DoPost(url string, data url.Values, extras (body []byte, err error)

func DoPostRaw

func DoPostRaw(url string, bodyType string, data interface{}, extras (body []byte, err error)

func EmbedWide

func EmbedWide(content string) string

内嵌 Wide iframe 版

func Exist

func Exist(filename string) bool

检查文件或目录是否存在 如果由 filename 指定的文件或目录存在则返回 true,否则返回 false

func FetchRealUrl

func FetchRealUrl(uri string) (realUrl string)

FetchRealUrl 获取链接真实的URL(获取重定向一次的结果URL)

func Gravatar

func Gravatar(avatar string, emailI interface{}, size uint16, isHttps bool) string


func InSlice

func InSlice(i int, slice []int) bool

InSlice 判断 i 是否在 slice 中

func IsAjax

func IsAjax(ctx echo.Context) bool

func IsDir

func IsDir(filename string) bool

判断给定文件名是否是一个目录 如果文件名存在并且为目录则返回 true。如果 filename 是一个相对路径,则按照当前工作目录检查其相对路径。

func IsFile

func IsFile(filename string) bool

判断给定文件名是否为一个正常的文件 如果文件存在且为正常的文件则返回 true

func Max

func Max(x, y int) int

func Models2Intslice

func Models2Intslice(models interface{}, idField string) []int

model中类型提取其中的 idField(int 类型) 属性组成 slice 返回

func MonthDayNum

func MonthDayNum(t time.Time) int

MonthDayNum t 所在时间的月份总天数

func SafeHtml

func SafeHtml(s string) string

func ScanDir

func ScanDir(directory string) []string

列出指定路径中的文件和目录 如果目录不存在,则返回空slice

func SetCaptcha

func SetCaptcha(id string)

SetCaptcha 设置验证码

func Struct2Map

func Struct2Map(dest map[string]interface{}, src interface{}) error

func Substring

func Substring(str string, length int, suffix string) string


func TimeAgo

func TimeAgo(t time.Time) string

func UMin

func UMin(x, y int) int


func UnderscoreName

func UnderscoreName(name string) string


type String

type String struct {
	// contains filtered or unexported fields

String wraps a regular string with a small structure that provides more efficient indexing by code point index, as opposed to byte index. Scanning incrementally forwards or backwards is O(1) per index operation (although not as fast a range clause going forwards). Random access is O(N) in the length of the string, but the overhead is less than always scanning from the beginning. If the string is ASCII, random access is O(1). Unlike the built-in string type, String has internal mutable state and is not thread-safe.

func NewString

func NewString(contents string) *String

NewString returns a new UTF-8 string with the provided contents.

func (*String) At

func (s *String) At(i int) rune

At returns the rune with index i in the String. The sequence of runes is the same as iterating over the contents with a "for range" clause.

func (*String) Init

func (s *String) Init(contents string) *String

Init initializes an existing String to hold the provided contents. It returns a pointer to the initialized String.

func (*String) IsASCII

func (s *String) IsASCII() bool

IsASCII returns a boolean indicating whether the String contains only ASCII bytes.

func (*String) RuneCount

func (s *String) RuneCount() int

RuneCount returns the number of runes (Unicode code points) in the String.

func (*String) Slice

func (s *String) Slice(i, j int) string

Slice returns the string sliced at rune positions [i:j].

func (*String) String

func (s *String) String() string

String returns the contents of the String. This method also means the String is directly printable by fmt.Print.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier