goutils

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 23 Imported by: 1

README

goutils

Go Utils

常用功能放在goutils包 大的模块功能放在子包内

go mod tidy
go mod download

go get -u github.com/BurntSushi/toml
go get -u go.mongodb.org/mongo-driver

go list -m -json all
git tag -ln
git tag -a v0.0.7 -m "goutils-v0.0.7"
git push origin --tags

License

This project is under MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

View Source
const (
	B = 1
	K = 1024 * B
	M = 1024 * K
	G = 1024 * M
	T = 1024 * G
	P = 1024 * T
	E = 1024 * P
)
View Source
const URLSeparator = '/'

Variables

View Source
var (
	Validate                   = validator.Validate
	RegisterCustomValidateType = validator.RegisterCustomValidateType
)
View Source
var DefaultTimeFormart = "2006-01-02 15:04:05"
View Source
var Fmt = fmt.Sprintf

Fmt shorthand, XXX DEPRECATED

Functions

func CurrentProcessName added in v0.0.6

func CurrentProcessName() (string, error)

func DebugPrintInfo added in v0.0.4

func DebugPrintInfo(v reflect.Value)

func DeepCopy

func DeepCopy(dst, src interface{}) error

深拷贝

func DefaultDataDir added in v0.0.4

func DefaultDataDir(dirs ...string) string

DefaultDataDir is the default data directory

func EmptyDir added in v0.0.8

func EmptyDir(dir string) bool

空目录

func EnsureDir added in v0.0.4

func EnsureDir(dir string, mode os.FileMode) error

确保完整路径

func Exit added in v0.0.4

func Exit(s string)

exit app

func FileExist added in v0.0.8

func FileExist(path string) bool

file and folder

func FileNotExist added in v0.0.8

func FileNotExist(path string) bool

file and folder

func GetCurrentPath added in v0.0.8

func GetCurrentPath() string

返回当前可执行文件的路径 os.Getwd() 返回当前的 work dir 工作目录

func HomeDir added in v0.0.4

func HomeDir() string

func If added in v0.0.6

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

实现三元表达式的功能

func Inject added in v0.0.4

func Inject(obj interface{}, key string, val interface{}) error

反射注入(struct 结构体)

func IsStartLower added in v0.0.8

func IsStartLower(s string) bool

是否首字母小写

func IsStartUpper added in v0.0.8

func IsStartUpper(s string) bool

是否首字母大写

func LockPIDFile added in v0.0.6

func LockPIDFile(pidfile string) error

func Mac added in v0.0.8

func Mac() string

获取本机第一个不为空的MAC地址

func MergeSliceByte added in v0.0.7

func MergeSliceByte(ss ...[]byte) []byte

func MustWriteFile added in v0.0.4

func MustWriteFile(filePath string, contents []byte, mode os.FileMode)

func NonEmptyDir added in v0.0.8

func NonEmptyDir(dir string) bool

非空目录

func ReverseByte added in v0.0.7

func ReverseByte(arr []byte) []byte

func Rootify added in v0.0.4

func Rootify(path string, roots ...string) string

helper function to make dir creation independent of root dir

func StartLower added in v0.0.8

func StartLower(s string) string

首字母小写

func StartUpper added in v0.0.8

func StartUpper(s string) string

首字母大写

func TimeParse added in v0.0.8

func TimeParse(value string) (time.Time, error)

func TimeParseInLocation added in v0.0.8

func TimeParseInLocation(value string) (time.Time, error)

func TimeParseToUTC added in v0.0.8

func TimeParseToUTC(value string) (time.Time, error)

func TrapSignal added in v0.0.4

func TrapSignal(cb func())

TrapSignal catches the SIGTERM and executes cb function. After that it exits with code 1.

func URLJoin added in v0.0.6

func URLJoin(urls ...string) string

func UUID added in v0.0.6

func UUID() (string, error)

func UnlockPIDFile added in v0.0.8

func UnlockPIDFile(pidfile string) error

func WindowsAppData added in v0.0.8

func WindowsAppData() string

func WriteFile added in v0.0.4

func WriteFile(filePath string, contents []byte, mode os.FileMode) error

func WritePIDFile added in v0.0.6

func WritePIDFile(filepath string) error

Types

type DiskSize added in v0.0.8

type DiskSize uint64

func (DiskSize) String added in v0.0.8

func (s DiskSize) String() string

type FileLock added in v0.0.6

type FileLock struct {
	// contains filtered or unexported fields
}

func NewFileLock added in v0.0.6

func NewFileLock(dir string) *FileLock

func (*FileLock) Lock added in v0.0.6

func (l *FileLock) Lock() error

func (*FileLock) Unlock added in v0.0.6

func (l *FileLock) Unlock() error

type Message added in v0.0.4

type Message struct {
	Code int         `json:"code"`           //状态码
	Msg  string      `json:"msg,omitempty"`  //消息
	Data interface{} `json:"data,omitempty"` //结果数据
}

func NewErrorMessage added in v0.0.5

func NewErrorMessage(err error) *Message

func NewMessage added in v0.0.4

func NewMessage(code int, msg string, datas ...interface{}) *Message

func NewSuccessMessage added in v0.0.5

func NewSuccessMessage(datas ...interface{}) *Message

Jump to

Keyboard shortcuts

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