Documentation ¶
Index ¶
- Constants
- Variables
- func AbsolutePath() (string, error)
- func AppIs64Bit() bool
- func Assert(condition bool, msg string, code ...int)
- func Authcode(text string, params AuthcodeParam) (str string, err error)
- func Base64Decode(str string) ([]byte, error)
- func Base64Encode(b []byte) string
- func CheckErr(err error)
- func CheckFileIsExist(filename string) bool
- func CheckGISPointInArea(areaString string, pointLng string, pointLat string) bool
- func CheckRunnable(err error, runnable *bool)
- func CompareHashAndPassword(e string, p string) (bool, error)
- func Contain(obj interface{}, target interface{}) (bool, error)
- func ContainsInterface(haystack interface{}, needle interface{}) bool
- func ConvertGBKToUTF8(src string, srcCode string, tagCode string) string
- func CopyFile(srcName, dstName string) (written int64, err error)
- func DateFormat(format string, t time.Time) string
- func EnvAddPathFromRoot(path string)
- func Exists(path string) bool
- func FormatTimeStr(timeStr string) (string, error)
- func GbkToUtf8(s []byte) ([]byte, error)
- func GetCurrentTime() time.Time
- func GetCurrentTimeStr() string
- func GetIpFromAddress(addr string) string
- func GetLocaHonst() string
- func GetLocalIP() ([]string, error)
- func GetLocation(ip string) string
- func GetPortFromAddress(addr string) int
- func Getwd() string
- func HMacSHA256(s, key string) string
- func HTTPRequest(url string, method Method, args ...interface{}) (string, error)
- func HasError(err error, msg string, code ...int)
- func HttpGet(url string) (string, error)
- func HttpGetHttpCode(url string) (int, error)
- func HttpPost(url string, contentType string, body []byte) (string, error)
- func HttpPostUseHandle(url string, body []byte, httpRequestHandler HttpRequestHandler) (string, error)
- func IP2Long(ipstr string) (uint64, error)
- func IdsStrToIdsIntGroup(key string, c *gin.Context) []int
- func If[T any](condition bool, trueVal, falseVal T) T
- func IndexOf(obj interface{}, target interface{}) (int, error)
- func Int64Abs(n int64) int64
- func Int64ToString(e int64) string
- func IntAbs(n int) int
- func IntToString(e int) string
- func IsDateTime(dateTimeStr string) bool
- func IsDir(path string) bool
- func IsEmpty(val interface{}) (b bool)
- func IsFile(path string) bool
- func IsIP(ip string) bool
- func IsMac(mac string) bool
- func IsMobile(mobile string) bool
- func IsNotEmpty(val interface{}) (b bool)
- func IsPointInsidePolygon(point gisPoint, polygon []gisPoint) bool
- func IsProcessRunning(pid int) bool
- func IsProcessRunningLinux(pid int) bool
- func IsProcessRunningWin(pid int) bool
- func Keys(m map[string]interface{}) []string
- func LcFirst(str string) string
- func LogAsJson(v any)
- func LogIfError(err error)
- func LogListAsJson(vList []any)
- func Long2IP(ip uint32) string
- func MakeDirs(path string) error
- func MapKeyToSnakeCase(fromMap map[string]any) map[string]any
- func MapToOrderedMap(input map[string]interface{}) *orderedmap.OrderedMap
- func Md5Sum(text string) string
- func Md5V(str string) string
- func NewGISArea(points []gisPoint) *gisArea
- func NewRand() *rand.Rand
- func Now(f ...int) string
- func NumberCompare[T number](arg1, arg2 T) int
- func NumberEQ[T number](arg1, arg2 T) bool
- func NumberGT[T number](arg1, arg2 T) bool
- func NumberLT[T number](arg1, arg2 T) bool
- func NumberNGT[T number](arg1, arg2 T) bool
- func NumberNLT[T number](arg1, arg2 T) bool
- func PrintAsJson(v any)
- func PrintIfError(err error)
- func PrintListAsJson(vList []any)
- func QueryFetchConditionMap(query any, conditionMap map[string]interface{})
- func RSADecode(b, key []byte, t ...CertType) ([]byte, error)
- func RSAEncode(b, key []byte, t ...CertType) ([]byte, error)
- func RandArray(arr []string) string
- func RandRangeInt(min, max int) int
- func RandRangeInt32(min, max int32) int32
- func RandomInt(min, max int) int
- func RandomStr(length int) string
- func RangeArray(m, n int) (b []int)
- func ReadFileAll(filename string) (content []byte, err error)
- func ReflectCopyProperties(dst, src interface{}) (err error)
- func ReflectGetFieldValue[T any](data interface{}, fieldName string) T
- func ReflectSetFieldValue[T any](dst interface{}, fieldName string, value T) error
- func RemoveFilesWildCard(filesWildCard string)
- func Reverse(s string) string
- func RootPath() string
- func RsaDecode(b, rsaKey []byte, t ...CertType) ([]byte, error)
- func RsaEncode(b, rsaKey []byte, t ...CertType) ([]byte, error)
- func SHA256(s string) string
- func SaveImageDataToFileAutoType(imageFile string, imageData image.Image) error
- func SecondsToTimeFormat(seconds, f int) (timeStr string)
- func SliceContains[T comparable](s []T, e T) bool
- func SliceCovertToInterface[T any](sliceToCovert []T) []interface{}
- func SliceCovertToMap[KEY_TYPE comparable, DATA_TYPE any](sliceToCovert []DATA_TYPE, keyName string) map[KEY_TYPE]DATA_TYPE
- func SliceFilter[T SliceType](sliceToFilter []T, filterFunc func(item T) bool) []T
- func SliceGetEnd[T any](list []T) T
- func SliceRemoveDuplicateElement[T SliceType](sliceToRemoveDuplicate []T) []T
- func Split(str, match string) []string
- func SplitBySpaceTab(str string) []string
- func StrTimeDifferenceSeconds(strTime1, strTime2 string) (difference int, err error)
- func StrToInt(err error, index string) int
- func StrToLocalTime(value string) (time.Time, error)
- func StrToSnakeCase(str string) string
- func StrToTime(value string, zone ...bool) (time.Time, error)
- func StringIsEmpty(str string) bool
- func StringToBool(e string) (bool, error)
- func StringToFloat64(e string) (float64, error)
- func StringToFloat64NotError(e string) float64
- func StringToInt(e string) (int, error)
- func StringToInt64(e string) (int64, error)
- func StringToInt64NotError(e string) int64
- func StringToIntNotError(e string) int
- func StringToUInt64(e string) (uint64, error)
- func StringToUInt64NotError(e string) uint64
- func StructToJsonStr(e interface{}) (string, error)
- func StructToMap(item interface{}) map[string]interface{}
- func StructToOrderedMap(input interface{}) *orderedmap.OrderedMap
- func StructToStringMap(input interface{}) map[string]interface{}
- func TimeFormat(t time.Time, f int) (timeStr string)
- func TimeToSecond(timeStr string) int
- func ToCamelCase(s string) string
- func ToCamelCaseUcFirst(str string) string
- func TodayDate() string
- func Trim(str string) string
- func URLDecode(str string) (string, error)
- func URLEncode(params interface{}) string
- func UUID() (string, error)
- func UcFirst(str string) string
- func UintptrToString(stringPtr uintptr) string
- func UintptrToUTF8String(stringPtr uintptr) string
- func UnZipFirstFile(zipFile string) ([]byte, error)
- func Utf8ToGbk(s []byte) ([]byte, error)
- func ValidateIsEmpty(a interface{}) bool
- func Values(m map[string]interface{}) []interface{}
- func WeekDayIdx(date string) int
- func WeekDayIdxForHuman(date string) int
- func WriteFile(fileFullName string, content []byte) error
- func YesterdayDate() string
- func ZipContent(zipFile string, fileName string, content []byte) error
- func ZipDirFiles(zipFile, dir string) error
- type AuthCodeType
- type AuthcodeParam
- type CertType
- type HttpRequestHandler
- type Method
- type SliceType
Constants ¶
const AUTHCODE_KEY_DEFAULT = "abcdefghijklmnopqrstuvwxyz1234567890"
const HTTP_CONTENT_TYPE_JSON string = "application/json"
const HTTP_TIMEOUT_DEFAULT time.Duration = time.Second * 10
const OS_LINUX = "linux"
const OS_WIN = "windows"
Variables ¶
var MATCH_ALL_CAP = regexp.MustCompile("([a-z0-9])([A-Z])")
var MATCH_FIRST_CAP = regexp.MustCompile("(.)([A-Z][a-z]+)")
var MATCH_NON_ALPHA_NUMERIC = regexp.MustCompile(`[^a-zA-Z0-9]+`)
var MaxDecryptBlock = 128
MaxDecryptBlock rsa decode max length
var MaxEncryptBlock = 117
MaxEncryptBlock rsa encode max length
Functions ¶
func Authcode ¶
func Authcode(text string, params AuthcodeParam) (str string, err error)
Authcode Discuz Authcode golang version
func CheckFileIsExist ¶
func CheckGISPointInArea ¶
func CheckRunnable ¶
func ContainsInterface ¶ added in v1.0.6
func ContainsInterface(haystack interface{}, needle interface{}) bool
Contains item is in map/slice/array
func FormatTimeStr ¶
func GetCurrentTime ¶
func GetCurrentTimeStr ¶
func GetCurrentTimeStr() string
func GetIpFromAddress ¶
func GetPortFromAddress ¶
func HTTPRequest ¶
HTTPRequest request url request url method request method post or get args[0] type is map[string]string or string, request paramaters, \x00@ if upload file args[1] type is map[string]string, request headers args[2] type is bool, whether to return the result args[3] type is *http.Client, custom client
func HasError ¶
HasError 错误断言 当 error 不为 nil 时触发 panic 对于当前请求不会再执行接下来的代码,并且返回指定格式的错误信息和错误码 若 msg 为空,则默认为 error 中的内容
func HttpGetHttpCode ¶
func HttpPostUseHandle ¶ added in v1.0.6
func HttpPostUseHandle(url string, body []byte, httpRequestHandler HttpRequestHandler) (string, error)
发启HTTP请求, 可以使用请求处理器对请求进行一些初始化操作, 比如设置头部信息等
func If ¶
请注意它不能完全替代三元表达式, trueVal 和 falseVal 必须计算出来, 这意味着 If(len(list) > 0, list[0], 0) 这样使用时会因为 list 为空而产生异常
func IndexOf ¶
从 slice, array 中找到指定元素的索引 obj: 要查找的元素 target: 要查找的slice, array 成功时返回 索引, nil 失败时返回 -1, 错误
func Int64ToString ¶
func IntToString ¶
func IsNotEmpty ¶
func IsNotEmpty(val interface{}) (b bool)
func IsPointInsidePolygon ¶
func IsPointInsidePolygon(point gisPoint, polygon []gisPoint) bool
func IsProcessRunningWin ¶ added in v1.0.6
func LogIfError ¶
func LogIfError(err error)
func LogListAsJson ¶
func LogListAsJson(vList []any)
func MapKeyToSnakeCase ¶ added in v1.0.7
map 里的key从驼峰转下划线 主要用于查询条件转成实际数据库字段名
func MapToOrderedMap ¶ added in v1.0.2
func MapToOrderedMap(input map[string]interface{}) *orderedmap.OrderedMap
普通的MAP转换成有序MAP(顺手按KEY升序排序)
func NumberCompare ¶
func NumberCompare[T number](arg1, arg2 T) int
数字比较, 相等返回 0; arg1大于arg2返回 1; arg1小于arg2返回 -1;
func PrintAsJson ¶
func PrintAsJson(v any)
func PrintIfError ¶
func PrintIfError(err error)
func PrintListAsJson ¶
func PrintListAsJson(vList []any)
func QueryFetchConditionMap ¶ added in v1.0.7
从 查询条件 生成查询 map 一般用于生成查询条件, 给GORM的 Where() 用 query结构体每个属性都设置成指针类型 属性值不为空的就说明此属性的值要做为查询条件, 会被放到生成的 map 里 WARNING: 会忽略不是指针类型的字段, 如果要做到更灵活, 以后再扩展
func ReadFileAll ¶
func ReflectCopyProperties ¶ added in v1.0.6
func ReflectCopyProperties(dst, src interface{}) (err error)
属性复制
func ReflectGetFieldValue ¶ added in v1.0.6
获取指定属性的值
func ReflectSetFieldValue ¶ added in v1.0.6
设置指定属性的值
func SaveImageDataToFileAutoType ¶
保存 image.Image 数据到图片文件, 将用 go 官方的图片数据解析器自动判断数据格式, 也会用文件扩展名自动存成相应的图片类型
func SecondsToTimeFormat ¶ added in v1.0.7
秒数转换成具体的时间
func SliceContains ¶ added in v1.0.6
func SliceContains[T comparable](s []T, e T) bool
func SliceCovertToInterface ¶ added in v1.0.6
func SliceCovertToInterface[T any](sliceToCovert []T) []interface{}
func SliceCovertToMap ¶ added in v1.0.6
func SliceCovertToMap[KEY_TYPE comparable, DATA_TYPE any](sliceToCovert []DATA_TYPE, keyName string) map[KEY_TYPE]DATA_TYPE
切片 转换成 map 一般用于快速找到特定数据 比如查询出来的数据列表, 用ID做 map 的 key 使用者可以很方便的找到 ID 对应的数据 不需要去遍历整个列表
func SliceFilter ¶
func SliceGetEnd ¶
func SliceGetEnd[T any](list []T) T
func SliceRemoveDuplicateElement ¶ added in v1.0.6
func SliceRemoveDuplicateElement[T SliceType](sliceToRemoveDuplicate []T) []T
func SplitBySpaceTab ¶
SplitBySpaceTab splite by space or tab
func StrTimeDifferenceSeconds ¶ added in v1.0.7
两个字符串时期的时间差(秒)
func StrToLocalTime ¶
StrToLocalTime get time.Time from string
func StringIsEmpty ¶
func StringToBool ¶
func StringToInt ¶
func StringToInt64 ¶
func StringToInt64NotError ¶ added in v1.0.7
字符串转 int64, 不检测是否错误
func StringToUInt64 ¶ added in v1.0.7
func StringToUInt64NotError ¶ added in v1.0.7
字符串转 uint64, 不检测是否错误
func StructToJsonStr ¶
func StructToMap ¶
func StructToMap(item interface{}) map[string]interface{}
StructToMap struct convert to map
func StructToOrderedMap ¶ added in v1.0.2
func StructToOrderedMap(input interface{}) *orderedmap.OrderedMap
结构体转换成有序MAP(顺手按KEY升序排序)
func StructToStringMap ¶ added in v1.0.2
func StructToStringMap(input interface{}) map[string]interface{}
结构体转换成MAP
func TimeToSecond ¶
时间转成秒数, 用来作当天的工作安排类的计算, 比如 time 为 1:00 , 结果为 60 秒 支持 xx:xx:xx 和 xx:xx
func UintptrToString ¶
从指定的内存地址取出字符串 过程: 一个个字节取出, 直到为 0 值结束
func UnZipFirstFile ¶ added in v1.0.6
解压zip文件里第一个文件(用于只压缩了一个文件的zip包, 经常会碰到, 避免再输入文件名)
func WeekDayIdxForHuman ¶
获取日期是周几的索引, 以普通人的阅读方式返回索引, 星期一为1, 星期天为7, 失败时返回 -1
func WriteFile ¶
*
- 以覆盖的方式写文件, 文件不存在时自动创建属性默认设为 0644 *
- @param fileName 文件名
- @param content 文件内容 *
- @return 错误信息
func ZipContent ¶ added in v1.0.6
将指定目录下的所有文件压缩成一个zip文件
func ZipDirFiles ¶ added in v1.0.6
将指定目录下的所有文件压缩成一个zip文件
Types ¶
type AuthCodeType ¶
type AuthCodeType int
AuthCodeType auth code type
const ( // ENCODE encode str AUTHCODE_TYPE_ENCODE AuthCodeType = iota // DECODE decode str AUTHCODE_TYPE_DECODE )
type AuthcodeParam ¶
type AuthcodeParam struct { EncryptOrDecrypt AuthCodeType // 加密还是解密 Key string // 密钥 Expires uint // 过期时间, 秒 DynamicLen uint // 动态码长度 }
type HttpRequestHandler ¶ added in v1.0.6
type SliceType ¶
type SliceType interface{ comparable }