utils

package module
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: MIT Imports: 12 Imported by: 10

README

utils Build Status Build Status license codecov

此模块不再更新,部分功能分拆至 sliceutil、localeutil 和 source 三个模块中

utils 包提供了一些常用的 Go 函数

  • MD5 生成 md5 编码;
  • FileExists 判断文件或是目录是否存在;
  • Merge 合并多个同类型的数据;

localeutil:

  • GetSystemLanguageTag 获取当前系统的本地化信息;

source:

  • DumpGoSource 输出并格式化 Go 的源代码;
  • CurrentFile 相当于部分语言的 __FILE__
  • CurrentDir 相当于部分语言的 __DIR__
  • CurrentLine 相当于部分语言的 __LINE__
  • CurrentFunction 相当于部分语言的 __FUNCTION__

slliceutil:

  • HasDuplication 检测数组是否包含重复的值;

安装

go get github.com/issue9/utils

文档

Go Walker go.dev reference

版权

本项目采用 MIT 开源授权许可证,完整的授权说明可在 LICENSE 文件中找到。

Documentation

Overview

Package utils 一些常用功能的集合

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentDir deprecated added in v1.2.0

func CurrentDir() string

CurrentDir 获取`调用者`所在的目录

Deprecated: 请使用 source.CurrentDir 代替

func CurrentFile deprecated added in v1.2.0

func CurrentFile() string

CurrentFile 获取`调用者`所在的文件

Deprecated: 请使用 source.CurrentFile 代替

func CurrentFunction deprecated added in v1.2.0

func CurrentFunction() string

CurrentFunction 获取`调用者`所在的函数名

Deprecated: 请使用 source.CurrentFunction 代替

func CurrentLine deprecated added in v1.2.0

func CurrentLine() int

CurrentLine 获取`调用者`所在的行

Deprecated: 请使用 source.CurrentLine 代替

func CurrentPath deprecated added in v1.2.0

func CurrentPath(path string) string

CurrentPath 获取`调用者`所在目录的路径

Deprecated: 请使用 source.CurrentPath 代替

func DumpGoFile deprecated added in v1.1.0

func DumpGoFile(path, content string) error

DumpGoFile 输出 Go 源代码到 path

会对源代码作格式化。

Deprecated: 请使用 DumpGoSource 代替

func DumpGoSource deprecated added in v1.2.0

func DumpGoSource(path string, content []byte) error

DumpGoSource 输出 Go 源码到 path

会对源代码作格式化。

Deprecated: 请使用 source.DumpGoSource 代替

func FileExists

func FileExists(path string) bool

FileExists 判断文件或是文件夹是否存在

func GetSystemLanguageTag deprecated added in v1.3.0

func GetSystemLanguageTag() (language.Tag, error)

GetSystemLanguageTag 返回当前系统的本地化信息

*nix 系统会使用 LANG 环境变量中的值,windows 在 LANG 环境变量不存在的情况下,调用 GetUserDefaultLocaleName 函数获取。

Deprecated: 请使用 localeutil.SystemLanguageTag 代替

func HasDuplication added in v1.4.0

func HasDuplication(slice interface{}, eq func(i, j int) bool) int

HasDuplication 检测数组中是否包含重复的值

slice 需要检测的数组或是切片,其它类型会 panic; eq 对比数组中两个值是否相等,相等需要返回 true; 返回值表示存在相等值时,第二个值在数组中的下标值;

func MD5

func MD5(str string) string

MD5 将一段字符串转换成 md5 编码

func Merge

func Merge(deep bool, elems ...interface{}) error

Merge 合并所有的元素

后一个元素的非零值将取代前一个元素中的值。 deep 是否递归合并子元素。 合并的元素只支持结构体或是结构体指针。

func Round

func Round(v float64) int64

Round 对一个浮点数进行四舍五入取整

func SplitPath

func SplitPath(path string) []string

SplitPath 将路径按分隔符分隔成字符串数组。比如:

/a/b/c  ==>  []string{"a", "b", "c"}

func TraceStack deprecated

func TraceStack(level int, msg ...interface{}) (string, error)

TraceStack 返回调用者的堆栈信息

Deprecated: 请使用 source.TraceStack 代替

Types

This section is empty.

Jump to

Keyboard shortcuts

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