utils

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

*

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexOfToInt

func IndexOfToInt(list []int, target int) int

查找int数组,找到了返回对应下标,没有则返回 -1

func IndexOfToString

func IndexOfToString(list []string, target string) int

查找字符串数组,找到了返回对应下标,没有则返回 -1

func IndexOfToUint

func IndexOfToUint(list []uint, target uint) int

查找uint数组,找到了返回对应下标,没有则返回 -1

func ListFiltter

func ListFiltter(slice interface{}, function func(interface{}) bool) interface{}

*

  • 过滤数组(切片)
  • @Method ListFiltter 返回过滤后的切片
  • @Param slice 切片,可以是指针类型
  • @param function 如何过滤的具体操作

func ListFindIndex

func ListFindIndex(src interface{}, function func(i interface{}) bool) int

*

  • 获取对应数组的合适项的下标
  • @Method ListIIndexOf
  • @Param src interface{} 数组,可以是指针类型
  • @Param function func(i interface{}) bool 查询条件

func MD5Encode

func MD5Encode(val string) string

*

  • 创建MD5加密

func MD5Verify

func MD5Verify(sourceVal, encryptVal string) bool

*

  • 比对信息和加密信息是否一致

func PathResolve

func PathResolve(url ...string) string

*

  • 获取根目录下文件

func Recursion

func Recursion(function func() int) error

*

  • 递归函数
  • @Method Recursion
  • @Param

func StrToCamel

func StrToCamel(s string) string

转换为:AnyKindOfString

func StrToColonBase

func StrToColonBase(s string) string

将斜号转为冒号:/admin/base --> admin:base

func StrToHash

func StrToHash(s string) string

*

  • 将长字符串转为hash值

func StrToKebab

func StrToKebab(s string) string

转换为:any-kind-of-string

func StrToLowerCamel

func StrToLowerCamel(s string) string

转换为:anyKindOfString 首字母小写

func StrToSnake

func StrToSnake(s string) string

转换为:any_kind_of_string

func StrToSnakeIgnore

func StrToSnakeIgnore(s, ignore string) string

转换为:any_kind.of_string

func StructCopy

func StructCopy(src, dst interface{}) error

*

  • 相似结构体中相同类型的值进行赋值
  • @method StructCopy
  • @param {[type]} interface{} src 源结构体
  • @param {[type]} interface{} dst 需要被赋值的结构体

func StructFilter

func StructFilter(src interface{}, ignores []string) (interface{}, error)

*

  • 将结构体中的字段删除并返回新的结构体
  • @method StructFilter
  • @param {[type]} interface{} src 源结构体
  • @param {[type]} []string ignores 需要忽略的字段

func StructGetField

func StructGetField(src interface{}, key string) (interface{}, error)

*

  • 获取结构体中的属性
  • @method StructGetField
  • @param {[type]} interface{} src 源结构体
  • @param {[type]} string key 需要查找的字段 *

func StructToMap

func StructToMap(src interface{}, filterZero bool, isSnake bool) (map[string]interface{}, error)

*

  • 将结构体转为map对象,用于省略字段使用
  • @method StructToMap
  • @param {[type]} interface{} src 源结构体
  • @param {[type]} bool filterZero 是否过滤空值
  • @param {[type]} bool isSnake 是否转为蛇形字符串

func ToBevelColon

func ToBevelColon(s string, ignore []string) string

路径转冒号

func ToCamelInitCase

func ToCamelInitCase(s string, initCase bool) string

转驼峰字符串的实现方法

func ToScreamingDelimited

func ToScreamingDelimited(s string, delimiter uint8, ignore string, screaming bool) string

转蛇形字符串的实现方法

Types

type StructListDiffResult

type StructListDiffResult struct {
	Add     []interface{} // 新增项
	Del     []interface{} // 删除项
	Mod     []interface{} // 变更项
	ModToId []interface{} // 附带原始唯一值的变更项
	Same    []interface{} // 相同项
}

func ListToDiff

func ListToDiff(src interface{}, dst interface{}, compareKeys []string, only string) (StructListDiffResult, error)

*

  • 对比两个结构体切片的差异,将变更的部分标记出来。(用于gorm中间表的处理)
  • @param src interface{} 旧的切片
  • @param src interface{} 新的切片
  • @param compareKeys []string 数据变更项的key
  • @param only string 新值需要附带的旧值的唯一字段,例如:ID

Jump to

Keyboard shortcuts

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