util

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

README

util

多种工具函数

  • 三目运算
  • 数学相关计算
  • 字符串处理
  • 各类型的值获取
  • Charles数据解析,Edge网络请求数据处理
  • 进程判断

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseProgram

func CloseProgram(programName string) error

CloseProgram 关闭程序

func CompareFloat

func CompareFloat(f1, f2 float64) int

CompareFloat 比较Float64大小, f1<f2:-1, f1=f2:0, f1>f2:1,

func CompareInt

func CompareInt(i1, i2 int) int

CompareInt 比较Int大小, i1<i2:-1, i1=i2:0, i1>i2:1,

func DeepCopy added in v1.0.1

func DeepCopy(src interface{}) interface{}

DeepCopy 深拷贝

func DurationDes

func DurationDes(d time.Duration) string

DurationDes 时长描述

func ExcFuncAndCountTime

func ExcFuncAndCountTime(f func())

ExcFuncAndCountTime 采用defer后无法捕获异常

func FloatAvg

func FloatAvg(fs ...float64) float64

FloatAvg Float的平均值

func FloatMax

func FloatMax(fs ...float64) float64

FloatMax Float取最大值

func FloatMin

func FloatMin(fs ...float64) float64

FloatMin Float取最小值

func FloatPercentSliceToString

func FloatPercentSliceToString(fs []float64, split string) string

FloatPercentSliceToString 浮点百分比数组转字符串

func FloatSliceToString

func FloatSliceToString(fs []float64, split string) string

FloatSliceToString 浮点数数组转字符串

func GetDateFromString

func GetDateFromString(s string) (int, int, int)

GetDateFromString 从字符串获取日期,返回年月日

func GetFloatFromMap

func GetFloatFromMap(data map[string]interface{}, key string, otherKeys ...string) float64

GetFloatFromMap 通过多个Key从Map中获取Float64值

func GetFloatFromMapByDimKey

func GetFloatFromMapByDimKey(data map[string]interface{}, dimKey string) float64

GetFloatFromMapByDimKey 通过Key中的关键字从Map中获取Float64值

func GetFloatFromSlice

func GetFloatFromSlice(data []interface{}, index int) float64

GetFloatFromSlice 通过索引从切片中获取Float64值

func GetFloatFromV

func GetFloatFromV(v interface{}) float64

GetFloatFromV 从任意类型获取Float64值

func GetIMapFromMap

func GetIMapFromMap(data map[string]interface{}, key string, otherKeys ...string) map[string]interface{}

GetIMapFromMap 通过多个Key从Map中获取Map值

func GetIMapFromV

func GetIMapFromV(v interface{}) map[string]interface{}

GetIMapFromV 从任意类型获取Map值

func GetISliceFromMap

func GetISliceFromMap(data map[string]interface{}, key string, otherKeys ...string) []interface{}

GetISliceFromMap 通过多个Key从Map中获取Slice值

func GetISliceFromV

func GetISliceFromV(v interface{}) []interface{}

GetISliceFromV 从任意类型获取Slice值

func GetInt64FromMap

func GetInt64FromMap(data map[string]interface{}, key string, otherKeys ...string) int64

GetInt64FromMap 通过多个Key从Map中获取Int64值

func GetInt64FromMapByDimKey

func GetInt64FromMapByDimKey(data map[string]interface{}, dimKey string) int64

GetInt64FromMapByDimKey 通过Key中的关键字从Map中获取Int64值

func GetInt64FromSlice

func GetInt64FromSlice(data []interface{}, index int) int64

GetInt64FromSlice 通过索引从切片中获取Int64值

func GetInt64FromV

func GetInt64FromV(v interface{}) int64

GetInt64FromV 从任意类型获取Int64值

func GetIntFromMap

func GetIntFromMap(data map[string]interface{}, key string, otherKeys ...string) int

GetIntFromMap 通过多个Key从Map中获取Int值

func GetIntFromMapByDimKey

func GetIntFromMapByDimKey(data map[string]interface{}, dimKey string) int

GetIntFromMapByDimKey 通过Key中的关键字从Map中获取Int值

func GetIntFromSlice

func GetIntFromSlice(data []interface{}, index int) int

GetIntFromSlice 通过索引从切片中获取Int值

func GetIntFromV

func GetIntFromV(v interface{}) int

GetIntFromV 从任意类型获取Int值

func GetKxAddBValue

func GetKxAddBValue(k, b, x float64) float64

GetKxAddBValue y = kx + b

func GetMapValueSlice

func GetMapValueSlice(keys []string, m map[string]string) []string

GetMapValueSlice 获取Value值切片, 不存在的Key为空字符串

func GetPercent

func GetPercent(single, total int) float64

GetPercent 数量百分比, Int

func GetPercentFloat

func GetPercentFloat(single, total float64) float64

GetPercentFloat 数量百分比, Float

func GetPrice

func GetPrice(price float64, addRange float64) float64

GetPrice 获取增加涨跌幅后的价格(2位小数)

func GetProgramRootDir

func GetProgramRootDir() (string, error)

GetProgramRootDir 获取应用程序所在根目录

func GetStringFromMap

func GetStringFromMap(data map[string]interface{}, key string, otherKeys ...string) string

GetStringFromMap 通过多个Key从Map中获取String值

func GetStringFromMapByDimKey

func GetStringFromMapByDimKey(data map[string]interface{}, dimKey string) string

GetStringFromMapByDimKey 通过Key中的关键字从Map中获取String值

func GetStringFromSlice

func GetStringFromSlice(data []interface{}, index int) string

GetStringFromSlice 通过索引从切片中获取String值

func GetStringFromV

func GetStringFromV(v interface{}) string

GetStringFromV 从任意类型获取String值

func If

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

If If 三目表达,泛型

func IfFloat

func IfFloat(condition bool, trueVal, falseVal float64) float64

IfFloat 三目运算,返回Float64

func IfInt

func IfInt(condition bool, trueVal, falseVal int) int

IfInt 三目运算,返回Int

func IfString

func IfString(condition bool, trueVal, falseVal string) string

IfString 三目运算,返回String

func IfUInt64

func IfUInt64(condition bool, trueVal, falseVal uint64) uint64

IfUInt64 三目运算,返回Uint64

func IntMax

func IntMax(is ...int) int

IntMax Int取最大值 *

func IntMin

func IntMin(is ...int) int

IntMin Int取最小值

func IntSliceToString

func IntSliceToString(is []int, split string) string

IntSliceToString 整数数组转字符串

func InterfaceSliceToString

func InterfaceSliceToString(ss []interface{}, split string) string

InterfaceSliceToString object数组转字符串

func IsExeRunning

func IsExeRunning(exeName string) bool

IsExeRunning 程序是否运行,exeName:进程名称

func LetterMarkSecondLastChinese

func LetterMarkSecondLastChinese(str string) string

LetterMarkSecondLastChinese 字母标记倒数第二个汉字

func MapKeysSlice added in v1.0.2

func MapKeysSlice[K comparable, V any](m map[K]V) []K

MapKeysSlice 获取map的keys

func MapValuesSlice added in v1.0.2

func MapValuesSlice[K comparable, V any](m map[K]V) []V

MapValuesSlice 获取map的values

func MatchKeys

func MatchKeys(text string, keys []string) ([]int, map[int]string)

MatchKeys 匹配关键字 ([index], map[index]key)

func ParseBrowserHarJson

func ParseBrowserHarJson(harStr, tagUrl string, tagMethod string) (string, map[string]string, string, error)

ParseBrowserHarJson 解析从浏览器下载的网络请求JSON,提取第一个符合条件的请求的params、Header, response

func ParseBrowserHarJsonAll

func ParseBrowserHarJsonAll(harStr, tagUrl string, tagMethod string, first bool) ([]string, []map[string]string, []string, error)

ParseBrowserHarJsonAll ParseBrowserHarJson 解析从浏览器下载的网络请求JSON,提取所有符合条件的请求的params、Header, response, first=true只返回第一个

func ParseCharlesJson

func ParseCharlesJson(jsonStr, tagUrl string, tagMethod string) ([]string, error)

ParseCharlesJson 解析CharlesJson, 根据tagUrl、tagMethod返回response

func Pause

func Pause()

Pause 按回车键继续

func RemoveDuplicatedString

func RemoveDuplicatedString(slice []string) []string

RemoveDuplicatedString 去除重复的字符串

func RemoveNonNumeric

func RemoveNonNumeric(str string) string

RemoveNonNumeric 去除非数字部分 输入"abc123def456", 输出 "123456"

func SliceToMap added in v1.0.2

func SliceToMap[K comparable, V any](s []K, f func(k K) V) map[K]V

SliceToMap 将slice转换为map

func SolveBinaryEquations

func SolveBinaryEquations(a1, b1, c1, a2, b2, c2 float64) (float64, float64, bool)

SolveBinaryEquations 解二元一次方程组, 克莱姆法则

func StringSliceToString

func StringSliceToString(ss []string, split string) string

StringSliceToString 字符串数组转字符串

Types

This section is empty.

Jump to

Keyboard shortcuts

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