common

package module
v0.0.0-...-9f554ff Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: GPL-3.0 Imports: 41 Imported by: 5

README

go-common

golang通用方法

Documentation

Index

Constants

View Source
const (
	Date = "2006-01-02"

	Datetime  = "2006-01-02 15:04:05"
	Datetime2 = "2006-01-02T15:04:05Z07:00"

	Nanosecond  = 1
	Microsecond = 1000 * Nanosecond
	Millisecond = 1000 * Microsecond
	Second      = 1000 * Millisecond
	Minute      = 60 * Second
	Hour        = 60 * Minute
)

* * 时间格式化

View Source
const (
	EXTHTML = ".html"
	EXTXML  = ".xml"
	EXTJSON = ".json"
	EXTZIP  = ".zip"
	EXTIDOC = ".idoc"
	EXTZED  = ".zed"
	EXTPDF  = ".pdf"
)

ExtHTML ExtHTML

Variables

This section is empty.

Functions

func Add

func Add(a, b int) int

Add 加法

func Append

func Append(args ...string) string

Append 连接字符串,第一个是源字符串

func Byte2Object

func Byte2Object(by []byte, v interface{}) error

Byte2Object Byte2Object

func CheckBirthdayValid

func CheckBirthdayValid(nYear, nMonth, nDay int) bool

CheckBirthdayValid Check birthday's year month day valid.

func CheckProvinceValid

func CheckProvinceValid(citizenNo []byte) bool

CheckProvinceValid Check province code valid.

func Circle

func Circle(sourceImg, newImg string)

Circle 切成圆形

func Citizen15To18

func Citizen15To18(citizenNo15 []byte) []byte

Citizen15To18 Convert citizen 15 to 18.

func Clone

func Clone(src interface{}) interface{}

浅克隆,可以克隆任意数据类型,对指针类型子元素无法克隆 获取类型:如果类型是指针类型,需要使用Elem()获取对象实际类型 获取实际值:如果值是指针类型,需要使用Elem()获取实际数据 说白了,Elem()就是获取反射数据的实际类型和实际值

func Contains

func Contains(element interface{}, arrays interface{}) bool

Contains 判断是否包含

func CopyDir

func CopyDir(dst, src string) error

CopyDir 复制文件夹

func CopyFile

func CopyFile(dst, src string) error

CopyFile 复制

func Covent2Map

func Covent2Map(value interface{}) map[string]interface{}

Covent2Map 转换数组类型

func CoventArray

func CoventArray(value interface{}) (list []interface{})

CoventArray 转换数组类型

func CurDir

func CurDir() string

CurDir CurDir

func Decrypt

func Decrypt(decrypted string, key []byte) (string, error)

Decrypt Decrypt解密

func DeepClone

func DeepClone(src interface{}) interface{}

深度克隆,可以克隆任意数据类型

func Deserialize

func Deserialize(valueBytes []byte) (interface{}, error)

反序列化

func DiffFile

func DiffFile(left, right string) (diff string, same bool, err error)

DiffFile DiffFile

func Empty

func Empty(s string) bool

Empty 判断字符串是否为空

func Encrypt

func Encrypt(text string, key []byte) (string, error)

Encrypt Encrypt加密

func FileExists

func FileExists(filename string) bool

FileExists 文件是否存在

func FileOpen

func FileOpen(filename string) ([]byte, error)

FileOpen FileOpen

func FileToURLPath

func FileToURLPath(file string) string

FileToURLPath FileToURLPath

func FilteredSQLInject

func FilteredSQLInject(source string) bool

FilteredSQLInject 正则过滤sql注入的方法 参数 : 要匹配的语句

func Float64ToString

func Float64ToString(f float64) string

Float64ToString Float64ToString

func ForceCreateFile

func ForceCreateFile(filename string) *os.File

ForceCreateFile 创建文件

func ForeachFile

func ForeachFile(path string, pattern string, onFindFile func(fileName string) error) error

ForeachFile 列出目录下所有文件

func GetCitizenNoInfo

func GetCitizenNoInfo(citizenNo []byte) (birthday int64, isMale bool, addrMask int, err error)

GetCitizenNoInfo Get information from citizen number. Birthday, gender, province mask.

func GetFileInfo

func GetFileInfo(filename string) (name, ext string, en bool)

GetFileInfo GetFileInfo

func GetFilelist

func GetFilelist(path string) []string

GetFilelist 列出目录下所有文件路径

func GetHTTPFile

func GetHTTPFile(URL, filePath string) error

GetHTTPFile 从http读取文件

func GetInternetIP

func GetInternetIP() string

GetInternetIP 获取外网ip

func GetJSONString

func GetJSONString(i interface{}) string

GetJSONString 获取json字符串

func GetKeys

func GetKeys(m map[string]interface{}) []string

*

  • @Description:
  • @User: zlt-com <nohairs@gmail.com>
  • @Date: 2021-09-27 16:55:17
  • @param {map[string]interface{}} m
  • @return {*}

func GetRandomString

func GetRandomString(n int, letterBytes string) string

GetRandomString 生成随机字符串

func GetStructTagValue

func GetStructTagValue(value interface{}, tagName string) (title []string)

GetStructTagValue struct中tag的值

func GetlastModified

func GetlastModified(file string) time.Time

GetlastModified 最后修改时间

func HTTPGet

func HTTPGet(uri string) ([]byte, error)

HTTPGet get 请求

func Int64TString

func Int64TString(f int64) string

Int64TString Int64TString

func IntFromFloat64

func IntFromFloat64(x float64) int

IntFromFloat64 float转int

func IntFromInterface

func IntFromInterface(x interface{}) int

IntFromInterface IntFromInterface

func IsEmail

func IsEmail(email string) bool

IsEmail IsEmail

func IsFileSame

func IsFileSame(left, right string) bool

IsFileSame IsFileSame

func IsLeapYear

func IsLeapYear(nYear int) bool

IsLeapYear IsLeapYear

func IsMobile

func IsMobile(mobile string) bool

IsMobile IsMobile

func IsValidCitizenNo

func IsValidCitizenNo(citizenNo *[]byte) bool

IsValidCitizenNo Check citizen number valid.

func IsValidCitizenNo18

func IsValidCitizenNo18(citizenNo18 *[]byte) bool

IsValidCitizenNo18 Check citizen number 18 valid.

func JSON2Map

func JSON2Map(jsonStr string) map[string]float64

JSON2Map JSON2Map

func JSON2Object

func JSON2Object(js string, v interface{}) (interface{}, error)

JSON2Object 类型转换

func ListDir

func ListDir(path string) []string

ListDir ListDir

func ListDirFilenane

func ListDirFilenane(path string) []string

ListDirFilenane ListDirFilenane

func MD5

func MD5(source string) string

MD5 加密

func Minus

func Minus(a, b int) int

Minus 减法

func NoneError

func NoneError(err error)

NoneError NoneError

func NotEmpty

func NotEmpty(s string) bool

NotEmpty NotEmpty

func Object2Byte

func Object2Byte(v interface{}) []byte

Object2Byte Object2Byte

func Object2JSON

func Object2JSON(obj interface{}) string

Object2JSON Object2JSON

func PathExists

func PathExists(path string) bool

PathExists 文件是否存在

func PostFile

func PostFile(fieldname, filename, uri string) ([]byte, error)

PostFile 上传文件

func PostJSON

func PostJSON(uri string, obj interface{}) ([]byte, error)

PostJSON post json 数据请求

func PostJSONWithRespContentType

func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, error)

PostJSONWithRespContentType post json数据请求,且返回数据类型

func PostMultipartForm

func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte, err error)

PostMultipartForm 上传文件或其他多个字段

func PostXML

func PostXML(uri string, obj interface{}) ([]byte, error)

PostXML perform a HTTP/POST request with XML body

func PostXMLWithTLS

func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error)

PostXMLWithTLS perform a HTTP/POST request with XML body and TLS

func PrintExcel

func PrintExcel(xlsxFile string)

PrintExcel PrintExcel

func ReadExcelFile

func ReadExcelFile(filename string) (allRows [][]string, err error)

ReadExcelFile ReadExcelFile

func ReadFile

func ReadFile(filename string) ([]string, error)

ReadFile ReadFile

func ReadFile2String

func ReadFile2String(filename string) (string, error)

ReadFile2String ReadFile2String

func ReadFileContext

func ReadFileContext(path string) string

ReadFileContext 读文件内容

func ReadJSON

func ReadJSON(obj interface{}, filename string) error

ReadJSON 文件转json

func ReadString

func ReadString(str string) []string

ReadString ReadFile

func ReadXML

func ReadXML(obj interface{}, filename string) error

ReadXML ReadXML

func ReflectFilde

func ReflectFilde(i interface{}, name string) (field interface{})

反射字段值

func ReflectFildes

func ReflectFildes(i interface{}) (field map[string]interface{})

反射字段值

func ReflectInterfaceName

func ReflectInterfaceName(i interface{}) string

func ReflectInterfaceTypeValue

func ReflectInterfaceTypeValue(i interface{}) (reflectType reflect.Type, reflectValue reflect.Value)

func ReflectMethod

func ReflectMethod(i interface{}, name string) []reflect.Value

反射字段值

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(arr []string) (newArr []string)

数组去重

func RemoveFile

func RemoveFile(file string)

RemoveFile RemoveFile

func SHA1EncodeFileName

func SHA1EncodeFileName(filename string) string

SHA1EncodeFileName SHA1EncodeFileName

func SaveFile

func SaveFile(file string, content string)

SaveFile 保存文件

func SaveJSON

func SaveJSON(filename string, obj interface{}) error

SaveJSON json转文件

func SaveUtf8BomFile

func SaveUtf8BomFile(file string, content string)

SaveUtf8BomFile 保存utf-8 bom文件

func SaveXML

func SaveXML(filename string, obj interface{}) error

SaveXML SaveXML

func ScanFiles

func ScanFiles(dir string, fileType []string) []string

ScanFiles ScanFiles

func Seize

func Seize(s interface{}, se string, pos, length int) string

Seize 占位方法 s 原始字符串 se 占位符 pos 位置,0:前 1:后 length 共几位

func Serialize

func Serialize(value interface{}) ([]byte, error)

序列化

func SetLastModified

func SetLastModified(file string, time time.Time)

SetLastModified 最后修改时间

func ShowError

func ShowError(err error)

ShowError ShowError

func Split

func Split(s string, sep string) []interface{}

Split 分割字符串,返回interface

func Splits

func Splits(s string, sep string) []string

Splits 分割字符串,返回string

func Start

func Start()

Start Start

func StrToUInt

func StrToUInt(str string) uint

StrToUInt 字符串转uint

func String

func String(i interface{}) string

func StringToUint

func StringToUint(strNumber string, value interface{}) (err error)

StringToUint 字符串转uint

func Struct2Arrary

func Struct2Arrary(i interface{}) (kv []interface{})

Struct2Arrary 反射模型所有属性

func Time2Timestamp

func Time2Timestamp(t string) int64

Time2Timestamp 字符串转时间戳

func Timestamp2Time

func Timestamp2Time(timestamp int64, format string) string

Timestamp2Time 时间戳转字符串

func Timestamp2Time2

func Timestamp2Time2(timestamp int64) string

Timestamp2Time2 时间戳转字符串

func UNCPath

func UNCPath(path string) string

UNCPath UNCPath

func URLToLocalFile

func URLToLocalFile(path string) string

URLToLocalFile URLToLocalFile

func Uint8FromInt

func Uint8FromInt(n int) (uint8, error)

Uint8FromInt int转unit

func UnicodeEmojiCode

func UnicodeEmojiCode(s string) string

UnicodeEmojiCode 表情转换

func UnicodeEmojiDecode

func UnicodeEmojiDecode(s string) string

UnicodeEmojiDecode 表情解码

func WriteFile

func WriteFile(file string, data []byte)

WriteFile 文件写

func Years

func Years(start, end int) []int

Years 获取年限数组

func ZeroPadding

func ZeroPadding(ciphertext []byte, blockSize int) []byte

ZeroPadding ZeroPadding

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

ZeroUnPadding ZeroUnPadding

func Zuijin

func Zuijin(this int, arr []int) int

Zuijin 整形 Zuijin 最接近this的数

Types

type CircleMask

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

CircleMask CircleMask

func NewCircleMask

func NewCircleMask(img image.Image, p image.Point, d int) CircleMask

NewCircleMask NewCircleMask

func (CircleMask) At

func (ci CircleMask) At(x, y int) color.Color

At At

func (CircleMask) Bounds

func (ci CircleMask) Bounds() image.Rectangle

Bounds Bounds

func (CircleMask) ColorModel

func (ci CircleMask) ColorModel() color.Model

ColorModel ColorModel

type MultipartFormField

type MultipartFormField struct {
	IsFile    bool
	Fieldname string
	Value     []byte
	Filename  string
}

MultipartFormField 保存文件或其他字段信息

Jump to

Keyboard shortcuts

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