utils

package
v0.0.0-...-2242553 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSingleQuotes

func AddSingleQuotes(data interface{}) string

AddSingleQuotes : 添加单引号

func Empty

func Empty(arg interface{}) bool

Empty : 是否位假

func FailReturn

func FailReturn(args ...interface{}) interface{}

FailReturn : 接口失败返回

func GetType

func GetType(params interface{}) string

GetType : 获取数据类型字符串 (string, int, float64, []int, []string, map[string]int ...) GetType : (能不用则不用,由于涉及到使用reflect包,性能堪忧)

func If

func If(condition bool, trueVal, falseVal interface{}) interface{}

If : ternary operator (三元运算) condition:比较运算 trueVal:运算结果为真时的值 falseVal:运算结果为假时的值 return: 由于不知道传入值的类型, 所有, 必须在接收结果时, 指定对应的值类型

func Implode

func Implode(data interface{}, glue string) string

Implode : 字符串转数组, 接受混合类型, 最终输出的是字符串类型

func InArray

func InArray(needle interface{}, hystack interface{}) bool

InArray :给定元素值 是否在 指定的数组中

func JsonEncode

func JsonEncode(data interface{}) (string, error)

JsonEncode : json转码

func ParseStr

func ParseStr(data interface{}) string

ParseStr 转换为string

func SuccessReturn

func SuccessReturn(args ...interface{}) interface{}

SuccessReturn : 接口成功返回 args: 传入的值,可接收1~3个值,第一个值是返回的数据,第二个值是状态码,第三个值是附加额外数据.

这里第二个值默认缺省为200(成功), 第三个值默认缺省为空

example: SuccessReturn([]map[string]interface{{"id":1,"name":"fizz"},{"id":2,"name":"fizz2"}}, 200, map[string]int{"page":1,"total":93,"limit":10}) return: {"data":[{"id":1,"name":"fizz"},{"id":2,"name":"fizz2"}], "status":200, "ext":{"page":1,"total":93,"limit":10}}

func UcFirst

func UcFirst(arg string) string

UcFirst : 字符串第一个字母转成大写

Types

This section is empty.

Jump to

Keyboard shortcuts

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