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 Contains(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 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 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 Keys(m map[string]interface{}) []string
- func LogAsJson(v any)
- func LogIfError(err error)
- func LogListAsJson(vList []any)
- func Long2IP(ip uint32) string
- func MakeDirs(path string) error
- 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 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 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 SliceFilter[T SliceType](sliceToFilter []T, filterFunc func(item T) bool) []T
- func SliceGetEnd[T any](list []T) T
- func Split(str, match string) []string
- func SplitBySpaceTab(str string) []string
- func StrToInt(err error, index string) int
- func StrToLocalTime(value string) (time.Time, error)
- 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 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 TodayDate() string
- func Trim(str string) string
- func URLDecode(str string) (string, error)
- func URLEncode(params interface{}) string
- func UUID() (string, error)
- func UintptrToString(stringPtr uintptr) string
- func UintptrToUTF8String(stringPtr uintptr) string
- 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
- type AuthCodeType
- type AuthcodeParam
- type CertType
- 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
Variables ¶
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 Contains ¶
func Contains(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 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 LogIfError ¶
func LogIfError(err error)
func LogListAsJson ¶
func LogListAsJson(vList []any)
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 ReadFileAll ¶
func SaveImageDataToFileAutoType ¶
保存 image.Image 数据到图片文件, 将用 go 官方的图片数据解析器自动判断数据格式, 也会用文件扩展名自动存成相应的图片类型
func SliceFilter ¶
func SliceGetEnd ¶
func SliceGetEnd[T any](list []T) T
func SplitBySpaceTab ¶
SplitBySpaceTab splite by space or tab
func StrToLocalTime ¶
StrToLocalTime get time.Time from string
func StringIsEmpty ¶
func StringToBool ¶
func StringToInt ¶
func StringToInt64 ¶
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 WeekDayIdxForHuman ¶
获取日期是周几的索引, 以普通人的阅读方式返回索引, 星期一为1, 星期天为7, 失败时返回 -1
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 SliceType ¶
type SliceType interface{ comparable }