utils

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 15 Imported by: 17

README

utils Build Status Build Status license codecov

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

  • MD5 生成 md5 编码;
  • FileExists 判断文件或是目录是否存在;
  • Merge 合并多个同类型的数据;
  • GetSystemLanguageTag 获取当前系统的本地化信息;
  • DumpGoSource 输出并格式化 Go 的源代码;
  • CurrentFile 相当于部分语言的 __FILE__
  • CurrentDir 相当于部分语言的 __DIR__
  • CurrentLine 相当于部分语言的 __LINE__
  • CurrentFunction 相当于部分语言的 __FUNCTION__
  • HasDuplication 检测数组是否包含重复的值;

安装

go get github.com/issue9/utils

文档

Go Walker go.dev reference

版权

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

Documentation

Overview

Package utils 一些常用的函数集合。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentDir added in v1.2.0

func CurrentDir() string

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

相当于部分语言的 __DIR__

func CurrentFile added in v1.2.0

func CurrentFile() string

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

相当于部分语言的 __FILE__

func CurrentFunction added in v1.2.0

func CurrentFunction() string

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

相当于部分语言的 __FUNCTION__

func CurrentLine added in v1.2.0

func CurrentLine() int

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

相当于部分语言的 __LINE__

func CurrentPath added in v1.2.0

func CurrentPath(path string) string

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

类似于部分语言的的 __DIR__ + "/" + path

func DumpGoFile deprecated added in v1.1.0

func DumpGoFile(path, content string) error

DumpGoFile 输出 Go 源代码到 path

会对源代码作格式化。

Deprecated: 请使用 DumpGoSource 代替

func DumpGoSource added in v1.2.0

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

DumpGoSource 输出 Go 源码到 path

会对源代码作格式化。

func FileExists

func FileExists(path string) bool

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

func GetSystemLanguageTag added in v1.3.0

func GetSystemLanguageTag() (language.Tag, error)

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

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

func HasDuplication added in v1.4.0

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

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

Example
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(HasDuplication(intSlice, func(i, j int) bool {
	return intSlice[i] == intSlice[j]
}))
Output:

6

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

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

TraceStack 返回调用者的堆栈信息

Types

This section is empty.

Directories

Path Synopsis
internal
syslocale
Package syslocale 获取所在系统的本地化语言信息
Package syslocale 获取所在系统的本地化语言信息

Jump to

Keyboard shortcuts

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