fc

package module
v0.0.0-...-9a1677b Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2020 License: MIT Imports: 32 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CAPTION_NUM = 50 //定义容量
)

支持以下4种类型:

ArrayToSimple([]*User , "Name")
ArrayToSimple([]User , "Name")
//需要注意map 是无序的
ArrayToSimple(map[interface{}]*User , "Name")
ArrayToSimple(map[interface{}]User , "Name")

Variables

View Source
var (
	CONTINUE_ERR = errors.New("continue")
)

Functions

func Addslashes

func Addslashes(str string) string

Returns a string with backslashes added before characters that need to be escaped. These characters are:

single quote (') double quote (") backslash (\)

func ArrayToSimple

func ArrayToSimple(data interface{}, key string) (res []string, err error)

func AttachFileDirectory

func AttachFileDirectory(fpath string) error

func Bin2hex

func Bin2hex(raw string) string

func BuildTimeInterval

func BuildTimeInterval(start, end time.Time) []string

包含end 天

func ByteFormat

func ByteFormat(i float64) string

func CheckHexAndLength

func CheckHexAndLength(v string, l int) bool

func CheckHexValid

func CheckHexValid(vs string) bool

func CheckIntSliceEqual

func CheckIntSliceEqual(x, y []int) bool

检测slice []int是否相等

func CheckMd5

func CheckMd5(v string) bool

检测MD5

func CheckSha1

func CheckSha1(v string) bool

检测sha1

func CheckSha256

func CheckSha256(v string) bool

检测sha256

func CheckStringSliceEqual

func CheckStringSliceEqual(x, y []string) bool

检测slice []string是否相等

func Chr

func Chr(c rune) string

func ColorDump

func ColorDump(c *color.Color, vals ...interface{})

c := color.New(color.FgCyan).Add(color.Underline) c := color.New(color.FgCyan, color.Bold) https://github.com/fatih/color

func Computation

func Computation(data interface{}, keyField, valueField string) (res map[string]string, err error)

存在覆盖的情况

func CopyFileContents

func CopyFileContents(src, dst string) (err error)

func DataTrunKey

func DataTrunKey(data interface{}, key string) (res map[string]interface{}, err error)

DataTrunKey使用示例:

需要注意:

  1. map 是无序的 , 返回结果全部都是无序的
  2. 重复的key 会被覆盖,请尽量保证没有重复的key

示例:

DataTrunKey([]*User , "Name")
DataTrunKey([]User , "Name")
DataTrunKey(map[interface{}]*User , "Name")
DataTrunKey(map[interface{}]User , "Name")

func DataTrunMulti

func DataTrunMulti(data interface{}, key string) (res map[string][]interface{}, err error)

func DebugTrace

func DebugTrace() []string

返回tracedebug 函数调用栈路径信息 文件名+行号+函数名

func Dump

func Dump(vals ...interface{})

The same as PHP:var_dump() https://www.php.net/var_dump

func EndIntSlice

func EndIntSlice(arr []int) (res int)

func EndStringSlice

func EndStringSlice(arr []string) (res string)

返回最后一个元素

func ErrSlice2Err

func ErrSlice2Err(es []error) error

func FieldExists

func FieldExists(fieldName string, ptr interface{}) bool

检测字段是否存在 支持[private]字段检测 支持[public]字段检测

func FileGet

func FileGet(filename string) ([][]byte, error)

func FileSize

func FileSize(filename string) int64

get file size by filepath

func FileStrings

func FileStrings(filename string) ([]string, error)

func FormatDateInt64

func FormatDateInt64(v int64) (string, error)

func FormatDateString

func FormatDateString(unix string) (string, error)

func Fstrtotime

func Fstrtotime(dateStr string) (T time.Time, err error)

示例: " 2018-03-01 " "2018-03-01 14:57:51"

func GbkToUtf8

func GbkToUtf8(v string) string

func GetBeforeDayTimer

func GetBeforeDayTimer(day int64) time.Time

相减获取对应的time.Time

func GetDayTimer

func GetDayTimer(day int64) time.Time

获取对应的天数

func GetLocalHostIPv4

func GetLocalHostIPv4() (string, error)

func GetTodayTimer

func GetTodayTimer() time.Time

返回当天 00:00:00 对应的time.Time

func GetWhereCondition

func GetWhereCondition(kws map[string]interface{}) (s string)

map where condition to string

func GetYesterdayTimer

func GetYesterdayTimer() time.Time

获取昨天的Time

func Hash

func Hash(v []byte) uint32

func Hex2bin

func Hex2bin(raw string) string

func HexDump

func HexDump(raw string) string

func InArrayInts

func InArrayInts(a int, arr []int) bool

元素存在数组检测函数

func InStringArray

func InStringArray(v string, arr []string) bool

func IntersectKeys

func IntersectKeys(s1, s2 []string) (s []string)

返回s1中每个元素 可以在s2中的检索到的值 eg : s1 = ["a" , "b" , "c"] ; s2 = ["a+t" , "b+t"] => ["a","b"]

func IsArray

func IsArray(value interface{}) bool

func IsCanUtf8ToGbk

func IsCanUtf8ToGbk(s string) bool

IsCanUtf8ToGbk 可以针对一些unicode 转换后的内容进一步判断,是否还需要再做一次转换

func IsDomain

func IsDomain(s string) bool

判断是否是域名 是返回true 不是返回false

func IsExist

func IsExist(filename string) bool

check filepath is exists if exists return true else return false

func IsIp

func IsIp(s string) bool

func IsPtr

func IsPtr(value interface{}) bool

判断是否是指针

func IsReadable

func IsReadable(name string) bool

check file or dir is readable

func IsSetQueryFieldParentMd5

func IsSetQueryFieldParentMd5(query *sj.Json) bool

特殊逻辑, 用于检测proc_chain是否传入parent_md5

func IsSlice

func IsSlice(v interface{}) bool

判断传入的元素是否是slice 支持检测 []string, []int , []int64 , []in32 , []interface{} , []float64 , []uint32 , []uint64 , ...

func IsUtf8

func IsUtf8(s string) bool

IsUtf8 判断是否是utf8

func IsWriteable

func IsWriteable(name string) bool

check file or dir is writeable

func IssetSlice

func IssetSlice(val interface{}, key int) bool

判断slice中的数组下标是否存在

func JsonBytesLength

func JsonBytesLength(jsons []*sj.Json) int64

获取json对应的实际大小

func JsonDecode

func JsonDecode(j interface{}) string

用于查看对应json结果的字符串表示

func JsonDecodes

func JsonDecodes(js []*sj.Json) (arr []string)

多个数组json处理

func JsonDump

func JsonDump(v interface{}) string

传入结构体, 可以打印出来格式化后的JSON 一般用于调试

func JsonMerge

func JsonMerge(j1, j2 *sj.Json) *sj.Json

返回第一个元素中没有的数据

func Md5

func Md5(str string) string

md5 计算

func Md5Bytes

func Md5Bytes(v []byte) string

func MemInfo

func MemInfo() (ret string)

统计mem

func MethodExists

func MethodExists(methodName string, ptr interface{}) bool

检测方法是否存在 不支持[private]方法检测 只支持[public]方法检测,私有方法无法检测出来

func Microtime

func Microtime() (float64, int64)

返回微秒 , unix

func MinInt

func MinInt(x, y int) int

返回较小的值

func MinInt64

func MinInt64(x, y int64) int64

返回较小的值

func Ord

func Ord(c string) []rune

func P

func P(vals ...interface{})

alias VarDump()

func ParseHostFromUrl

func ParseHostFromUrl(address string) (string, error)

解析domain

func ParseStr

func ParseStr(str string) url.Values
eg:

u := ParseStr("?username=zhangsan&passwd=123456") u.Get("username");

func Rand

func Rand(min, max int) int

Rand between [min ~ max]

func RandGenerator

func RandGenerator(n int) int

n 生成随机数的最大范围

func Random

func Random() float64

func RangeByte

func RangeByte(start, end rune, step int) (arr []byte)

example:

RangeByte('a', 'm', 1)
RangeByte('a', 'z', 2)

func RangeInt

func RangeInt(start, end, step int) (arr []int)

example:

RangeInt(0,10,1)
RangeInt(0,100,2)

func Round

func Round(value float64, precision int) (f float64)

func SaveFile

func SaveFile(path string, content []byte, bak bool) error

SaveFile data save to file

func ShuffleInt

func ShuffleInt(arr []int) []int

shuffle int slice

func SliceChunk

func SliceChunk(data []string, chunkSize int) (divided [][]string)

func SliceIntUnique

func SliceIntUnique(slice []int) []int

func SliceStringDiff

func SliceStringDiff(arr1 []string, arrs ...[]string) (data []string)

diff slice Compares arr1 against one or more other arrays and returns the values in arr1 that are not present in any of the other arrays.

func SliceStringIntersect

func SliceStringIntersect(a, b []string) []string

交集

func SliceStringMerge

func SliceStringMerge(a []string, b ...[]string) []string

去重+合并

func SliceStringUnion

func SliceStringUnion(a []string, b ...[]string) []string

并集

func SliceStringUnique

func SliceStringUnique(slice []string) []string

去重

func SliceToStringSlice

func SliceToStringSlice(v interface{}) (ret []string, err error)

任意[]interface{}转换为[]string []string => []string []int => []string []interface{} => []string []int32 => []string []uint32 => []string []uint64 => []string []floag64 => []string ...

func SplitByChar

func SplitByChar(smart, spChar1, spChar2 string) (data []string)

字符串两个切割符号支持 使用示例: SplitByChar(str , "&&" , "||");

func SplitComma

func SplitComma(path string) []string

"'ipinfo'.*.info.'city'": 4, "'ipinfo'.*.info.city": 4, "ipinfo.*.info.city": 4, "ipinfo.'*'.info.city": 4, "'1234.23.4.2'.ipinfo.'1.0.0.1001'.info.city": 5, "'ipinfo'.'1.0.0.1001'.info.name.val.'city'": 6, "ipinfo.'1.0.0.1001'.info.city.'a.b.c'": 5,

func SplitPath

func SplitPath(path string) (dir, name, typename string)

func Sql

func Sql(w string, values ...interface{}) string

Sql 构建sql

example:

sql := "select * from test where name=? and age =?  order by ? limit ?"
vs := []interface{}{
	"hello",
	1234,
	"id desc",
	"1,50",
}

func SqlWhere

func SqlWhere(w string, values ...interface{}) string

构建where 条件

example:

sql := "name=? and age =? and cname in(?) and tname in(?)"
vs := []interface{}{
	"hello",
	1234,
	[]interface{}{ "a", "b", "c" },
	[]string{ "d", "e", "f" },
}
SqlWhere(sql, vs...)

func StrToInt32

func StrToInt32(str string) (int32, error)

func StringToUnicode2

func StringToUnicode2(s string) string

字符串转码为unicode

func Stripslashes

func Stripslashes(str string) string

Un-quotes a quoted string.

func Strtotime

func Strtotime(format string, t time.Time) (T time.Time, err error)

示例:

t, _ = Strtotime("-1 day", time.Now())
t, _ = Strtotime("-1       day", time.Now())
t, _ = Strtotime(" -1  month ", time.Now())
t, _ = Strtotime(" -1  year ", time.Now())

func Substr

func Substr(str string, begin, length int) string

func SubstrCount

func SubstrCount(s, v string) int

统计字符串出现的次数

func ToString

func ToString(v interface{}) string

func URLDecode

func URLDecode(str string) (string, error)

URLDecode urldecode()

func URLEncode

func URLEncode(str string) string

URLEncode urlencode()

func Ucfirst

func Ucfirst(str string) string

首字母大写

func UnicodeToString

func UnicodeToString(s string) string

unicode转码为中文

func Uniqid

func Uniqid(prefix string) string

使用当前时间纳秒+hostname+pid的唯一ID prefix用于解决结果碰撞问题 length = 26

func UniqueKeys

func UniqueKeys(s1, s2 []string) (s []string)

返回s1中每个元素 无法在s2中的检索到的值 eg : s1 = ["a" , "b" , "c"] ; s2 = ["a+t" , "b+t"] => ["c"]

func Utf8ToGbk

func Utf8ToGbk(v string) string

func ValueFromPtr

func ValueFromPtr(field string, ptr interface{}) (interface{}, error)

func VarDump

func VarDump(vals ...interface{})

func ViperFile

func ViperFile(filepath string) error

Types

type F

type F func(reflect.Value, string) error

type MemDefine

type MemDefine []*mem.VirtualMemoryStat

Jump to

Keyboard shortcuts

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