说明
golang常用工具类封装📦
代码
包含判断
func Contains(str_array []string, target string) bool { for _, element := range str_array { if target == element { return true } } return false }
map 提取 key
func GetKeys(m map[string]([]string)) []string { keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } return keys }
map 提取 key
func GetKeysV2(m map[string](string)) []string { keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } return keys }
map 提取 value
func GetValues(m map[string]([]string)) []string { values := make([]string, 0, len(m)*5) for _, v := range m { values = Union(v, values) } return values } func GetValuesV2(m map[string]string) []string { var tempMap = make(map[string](int)) values := make([]string, 0, len(m)*5) for _, v := range m { _, ok := tempMap[v] if ok { continue } values = append(values, v) tempMap[v] = 1 } return values }
原地址: https://blog.csdn.net/qq_40374604/category_11938137.html