utils

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_DIR_MODE  = 0o755
	DEFAULT_FILE_MODE = 0o644
)
View Source
const (
	TAG_KEY_SEP   = "/"
	TAG_FIELD_SEP = ","
)

Variables

View Source
var (
	WeekEndType = calendar.W_MON_FRI // 双休

)

Functions

func ConcatWith

func ConcatWith(master, slave string) string

ConcatWith 用:号连接两个部分,如果后一部分也存在的话

func CopyDir

func CopyDir(src, dst string) (err error)

CopyDir 通过Bash命令复制整个目录,只能运行于Linux或MacOS 当dst结尾带斜杠时,复制为dst下的子目录

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies the contents of the file named src to the file named by dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file.

func CreateFile

func CreateFile(path string) (fp *os.File, err error)

func CreateMd5Password

func CreateMd5Password(password string) string

func CreatePassword

func CreatePassword(password string) string

func CreateToken

func CreateToken(prefix []byte, tailsize int) string

func FileSize

func FileSize(path string) (int64, bool)

FileSize detect if file exists -1, false 不合法的路径 0, false 路径不存在 -1, true 存在文件夹 >=0, true 文件并存在

func FindFiles

func FindFiles(dir, ext string) (map[string]os.FileInfo, error)

FindFiles 遍历目录下的文件,递归

func GetChangesFor

func GetChangesFor(v interface{}, changes map[string]interface{}) map[string]interface{}

func GetColumns

func GetColumns(v interface{}, alias string, cols []string) []string

func GetFinalType

func GetFinalType(v interface{}) (rt reflect.Type)

func GetFirstFile

func GetFirstFile(fileNames []string, minSize int64) string

GetFirstFile 逐个尝试,找出第一个存在的文件

func GetIndirectType

func GetIndirectType(v interface{}) (rt reflect.Type)

func GetNextWorkday

func GetNextWorkday(t time.Time) (time.Time, bool)

GetNextWorkday 找出下一个工作日(不含今天)

func GetPasswordChanges

func GetPasswordChanges(password string) map[string]interface{}

func IsHoliday

func IsHoliday(date string) bool

IsHoliday 判断是否节假日,日期使用yyyy-mm-dd格式

func ListFiles

func ListFiles(dir, ext string) (map[string]os.FileInfo, error)

ListFiles 找出目录下的文件,不含子目录

func Md5

func Md5(data string) string

func MkdirForFile

func MkdirForFile(path string, force bool) (size int64)

MkdirForFile 为文件路径创建目录

func NewSerialNo

func NewSerialNo(n byte) string

func NewTimeSerialNo

func NewTimeSerialNo(n byte, t time.Time) string

func OpenFile

func OpenFile(path string, readonly, append bool) (fp *os.File, size int64, err error)

func QuoteColumns

func QuoteColumns(cols []string, sep string, quote func(string) string) string

QuoteColumns 盲转义,认为字段名以小写字母开头

func ReduceSpaces

func ReduceSpaces(s string) string

ReduceSpaces 将多个连续空白缩减为一个空格

func RemoveSpaces

func RemoveSpaces(s string) string

RemoveSpaces 删除所有空白,包括中间的

func ReplaceWith

func ReplaceWith(s string, subs map[string]string) string

ReplaceWith 一一对应进行替换,次序不定(因为map的关系)

func SetCalendarY2019

func SetCalendarY2019(cal *calendar.Calendar) *calendar.Calendar

SetCalendarY2019 2019年节日调休年历

func SetCalendarY2020

func SetCalendarY2020(cal *calendar.Calendar) *calendar.Calendar

SetCalendarY2020 2020年节日调休年历

func SortedKeys

func SortedKeys(data interface{}) (keys []string)

func SprintfString

func SprintfString(tpl string, data []string) string

func StrToList

func StrToList(data []string) []interface{}

StrToList 将字符串数组转为一般数组

func VerifyPassword

func VerifyPassword(plainText, cipherText string) bool

func WrapWith

func WrapWith(s, left, right string) string

WrapWith 如果本身不为空,在左右两边添加字符

Types

type Globs

type Globs []glob.Glob

func NewGlobs

func NewGlobs(wildcards []string) Globs

func (Globs) MatchAll

func (gs Globs) MatchAll(word string, forEmpty bool) bool

func (Globs) MatchAny

func (gs Globs) MatchAny(word string, forEmpty bool) bool

type ICipher

type ICipher interface {
	CreatePassword(plainText string) string
	VerifyPassword(plainText, cipherText string) bool
}

func Cipher

func Cipher() ICipher

type Itag

type Itag struct {
	reflect.StructTag
	// contains filtered or unexported fields
}

Itag Yet another StructTag

func NewItag

func NewItag() *Itag

func (*Itag) Append

func (it *Itag) Append(key, value string)

Append Sets a tag in the tag data map

func (Itag) Build

func (it Itag) Build(data []byte, name, value string) []byte

Build 转为字符串格式

func (*Itag) Burnish

func (it *Itag) Burnish(tag reflect.StructTag, names ...string)

Burnish 保留部分tags

func (*Itag) Delete

func (it *Itag) Delete(key string)

Delete Deletes a tag

func (Itag) Get

func (it Itag) Get(key string) string

Get returns the value associated with key in the tag string

func (Itag) Lookup

func (it Itag) Lookup(key string) (string, bool)

Lookup Returns a tag from the tag data

func (*Itag) Parse

func (it *Itag) Parse(tag reflect.StructTag)

Parse 解析全部tags

func (Itag) String

func (it Itag) String() string

String 转为字符串格式

type Word

type Word string

func (Word) MatchSubString

func (w Word) MatchSubString(subs string) (string, Word)

MatchSubString 寻找字符第一次出现的位置,类似IndexAny

func (Word) SkipAnyChar

func (w Word) SkipAnyChar(chars string) Word

SkipAnyChar 忽略开头字符

Jump to

Keyboard shortcuts

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