common

package module
v0.0.0-...-fef6b24 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 14 Imported by: 2

README

common

The common component for GoLang.

Documentation

Overview

Author: Kernel.Huang Mail: kernelman79@gmail.com File: FileService Date: 3/21/21 12:50 AM

Index

Constants

View Source
const DateFormat = "2006-01-02"
View Source
const MAX_ULIMIT = 65535
View Source
const MsTimeFormat = "2006-01-02 15:04:05.999"
View Source
const TimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var Array = new(ArrayUtil)
View Source
var String = new(StrUtil)
View Source
var Time = new(times)
View Source
var UUID = new(uid)

Functions

This section is empty.

Types

type ArrayUtil

type ArrayUtil struct{}

func (*ArrayUtil) EqIntSlice

func (a *ArrayUtil) EqIntSlice(source, target []int) bool

比较int切片是否相等

func (*ArrayUtil) EqStringSlice

func (a *ArrayUtil) EqStringSlice(source, target []string) bool

比较string切片是否相等

func (*ArrayUtil) ReverseRune

func (a *ArrayUtil) ReverseRune(runes []rune) []rune

反转[]rune数组

func (*ArrayUtil) ReverseStringArray

func (a *ArrayUtil) ReverseStringArray(arr []string) []string

反转[]string数组

func (*ArrayUtil) StringArrayOffsetToString

func (a *ArrayUtil) StringArrayOffsetToString(arr []string, need string, offset int) string

[]string数组转字符串

type FileServices

type FileServices struct {
	Perm    os.FileMode
	DirPerm os.FileMode
	// contains filtered or unexported fields
}

func (*FileServices) AddString

func (file *FileServices) AddString(content string) bool

*

  • 单次追加写入文本内容
  • 示例: Files.AddWrite(filePath).AddString("text")

func (*FileServices) AddWrite

func (file *FileServices) AddWrite(filename string) *FileServices

*

  • 追加写入模式

func (*FileServices) AppendWrite

func (file *FileServices) AppendWrite(filename string) *os.File

*

  • 追加写入模式
  • open := Files.AppendWrite(filePath)
  • defer func() {_ = open.Close()}()
  • write := bufio.NewWriter(open)
  • _, _ := write.WriteString("text")
  • _ = write.Flush()

func (*FileServices) BufIoPut

func (file *FileServices) BufIoPut(filename string, content string) bool

*

  • BufIO写入模式

func (*FileServices) CheckFileActive

func (file *FileServices) CheckFileActive(filename string) int64

*

  • 检查文件存活时间

func (*FileServices) CloseFile

func (file *FileServices) CloseFile() bool

*

  • 关闭文件句柄,使其无法用于I/O
  • 示例:
  • write := Files.AddWrite(filePath)
  • write.MultiAddString("text")
  • write.CloseFile()

func (*FileServices) Create

func (file *FileServices) Create(filename string) *os.File

*

  • 使用默认Perm:0666模式创建文件

func (*FileServices) CreateDir

func (file *FileServices) CreateDir(path string, perm ...os.FileMode) bool

*

  • 创建目录: path的所经过目录路径不存在则创建, 否则忽略

func (*FileServices) FileInfo

func (file *FileServices) FileInfo(filename string) os.FileInfo

func (*FileServices) FromByte

func (file *FileServices) FromByte(content []byte) bool

*

  • []byte写入方式
  • 示例: Files.PutFile(filePath).FromByte([]byte("text")

func (*FileServices) FromString

func (file *FileServices) FromString(str string) bool

*

  • 写入字符串内容
  • 示例: Files.PutFile(filePath).FromString("text")

func (*FileServices) GetFile

func (file *FileServices) GetFile(filename string) []byte

*

  • 读取文件内容

func (*FileServices) GetFileSize

func (file *FileServices) GetFileSize(filename string) int64

*

  • 获取文件大小

func (*FileServices) IoPut

func (file *FileServices) IoPut(filename string, content []byte) bool

*

  • []byte写入方式

func (*FileServices) IsExists

func (file *FileServices) IsExists(path string) error

*

  • 检查文件或目录是否存在,并返回错误

func (*FileServices) MultiAddString

func (file *FileServices) MultiAddString(content string) bool

*

  • 多次追加写入文本内容
  • 示例:
  • write := Files.AddWrite(filePath)
  • write.MultiAddString("text1")
  • write.MultiAddString("text2")
  • write.CloseFile()

func (*FileServices) NewDir

func (file *FileServices) NewDir(path string, perm ...os.FileMode) bool

*

  • 新建一个目录

func (*FileServices) NewFolder

func (file *FileServices) NewFolder(perm ...os.FileMode) bool

*

  • 新建一个目录

func (*FileServices) NewNonFolder

func (file *FileServices) NewNonFolder(perm ...os.FileMode) bool

*

  • 新建目录: path的所经过目录路径不存在则创建, 否则忽略

func (*FileServices) NewPath

func (file *FileServices) NewPath(path string) *FileServices

*

  • 路径赋值

func (*FileServices) Overwrite

func (file *FileServices) Overwrite(filename string) *os.File

*

  • 覆盖写入模式
  • 示例:
  • open := Files.AppendWrite(filePath)
  • defer func() {_ = open.Close()}()
  • write := bufio.NewWriter(open)
  • _, _ := write.WriteString("text")
  • _ = write.Flush()

func (*FileServices) PathExists

func (file *FileServices) PathExists(path string) bool

*

  • 检查文件或目录是否存在

func (*FileServices) PutFile

func (file *FileServices) PutFile(filename string) *FileServices

func (*FileServices) RecursionIterateDir

func (file *FileServices) RecursionIterateDir(path string, info os.FileInfo, node *fileNode, number *uint) error

*

  • 递归遍历目录

func (*FileServices) ShowFileTree

func (file *FileServices) ShowFileTree() *fileNode

*

  • 获取文件树列表

func (*FileServices) Write

func (file *FileServices) Write(perm ...os.FileMode) *os.File

*

  • Perm传参写入模式
  • 示例:
  • FileService.PutFile(path).Write()
  • FileService.PutFile(path).Write(0640)

type FormatServices

type FormatServices struct {
	From interface{}
	To   interface{}
}

func (*FormatServices) Base64ToByte

func (format *FormatServices) Base64ToByte() []byte

func (*FormatServices) Base64ToString

func (format *FormatServices) Base64ToString() string

func (*FormatServices) FromArrayString

func (format *FormatServices) FromArrayString(from []string) *FormatServices

func (*FormatServices) FromBase64

func (format *FormatServices) FromBase64(from interface{}) *FormatServices

func (*FormatServices) FromBsonM

func (format *FormatServices) FromBsonM(from interface{}) *FormatServices

func (*FormatServices) FromByte

func (format *FormatServices) FromByte(from []byte) *FormatServices

func (*FormatServices) FromInt

func (format *FormatServices) FromInt(from int) *FormatServices

func (*FormatServices) FromInt64

func (format *FormatServices) FromInt64(from int64) *FormatServices

func (*FormatServices) FromInterface

func (format *FormatServices) FromInterface(from interface{}) *FormatServices

func (*FormatServices) FromMapStringByte

func (format *FormatServices) FromMapStringByte(from map[string][]byte) *FormatServices

func (*FormatServices) FromMapStringInterface

func (format *FormatServices) FromMapStringInterface(from map[string]interface{}) *FormatServices

func (*FormatServices) FromRune

func (format *FormatServices) FromRune(from []rune) *FormatServices

func (*FormatServices) FromString

func (format *FormatServices) FromString(from string) *FormatServices

func (*FormatServices) InterfaceToArray

func (format *FormatServices) InterfaceToArray() []string

func (*FormatServices) ToArrayArrayInt

func (format *FormatServices) ToArrayArrayInt() [][]int

func (*FormatServices) ToArrayInt

func (format *FormatServices) ToArrayInt() []int

func (*FormatServices) ToArrayInterface

func (format *FormatServices) ToArrayInterface() []interface{}

func (*FormatServices) ToArrayMapStringInterface

func (format *FormatServices) ToArrayMapStringInterface() []map[string]interface{}

*

  • 待测试

func (*FormatServices) ToArrayString

func (format *FormatServices) ToArrayString() []string

func (*FormatServices) ToBase64

func (format *FormatServices) ToBase64() string

func (*FormatServices) ToBool

func (format *FormatServices) ToBool() bool

func (*FormatServices) ToByte

func (format *FormatServices) ToByte() []byte

func (*FormatServices) ToInt

func (format *FormatServices) ToInt() int

func (*FormatServices) ToInt64

func (format *FormatServices) ToInt64() int64

func (*FormatServices) ToMapIntInterface

func (format *FormatServices) ToMapIntInterface() map[int]interface{}

func (*FormatServices) ToMapStringByte

func (format *FormatServices) ToMapStringByte() map[string][]byte

func (*FormatServices) ToMapStringInterface

func (format *FormatServices) ToMapStringInterface() map[string]interface{}

func (*FormatServices) ToMapStringString

func (format *FormatServices) ToMapStringString() map[string]string

func (*FormatServices) ToRune

func (format *FormatServices) ToRune() []rune

func (*FormatServices) ToString

func (format *FormatServices) ToString() string

func (*FormatServices) ToUint

func (format *FormatServices) ToUint() uint

type StrUtil

type StrUtil struct{}

func (*StrUtil) Cull

func (s *StrUtil) Cull(str, need string) string

剔除字符串中指定字符

func (*StrUtil) IsNull

func (s *StrUtil) IsNull(str ...string) bool

判断多个字符串是否为空

func (*StrUtil) Reverse

func (s *StrUtil) Reverse(str string) string

反转字符串

func (*StrUtil) SplitGetBeforeSuffix

func (s *StrUtil) SplitGetBeforeSuffix(str string, need string, joinNeed string) string

分割字符串以获取字符串后缀之前的字符串

func (*StrUtil) SplitGetPrefix

func (s *StrUtil) SplitGetPrefix(str string, need string) string

分割字符串以获取字符串前缀

func (*StrUtil) SplitGetSuffix

func (s *StrUtil) SplitGetSuffix(str string, need string) string

分割字符串以获取字符串后缀

func (*StrUtil) SplitLineBreak

func (s *StrUtil) SplitLineBreak(path string) string

分割换行符以获取字符串

func (*StrUtil) SplitString

func (s *StrUtil) SplitString(path string, need string) string

分割字符串

func (*StrUtil) Sub

func (s *StrUtil) Sub(source string, start int, end int) string

截取字符串

func (*StrUtil) SubLen

func (s *StrUtil) SubLen(str string, pos int, length int) string

截取字符串

func (*StrUtil) ToLower

func (s *StrUtil) ToLower(str string) string

英文字符串全部转小写

func (*StrUtil) ToUpper

func (s *StrUtil) ToUpper(str string) string

英文字符串全部转大写

func (*StrUtil) UcFirst

func (s *StrUtil) UcFirst(str string) string

首字母大写

Jump to

Keyboard shortcuts

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