goutil

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

README

go-util

自己整理的一些常用工具类合集

Documentation

Overview

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:08
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:06
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:24
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:10
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:15
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:23
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:06
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:13
  • Desc:

==================================

==================================

  • Name:Jerry
  • DateTime:2019/5/17 13:11
  • Desc:

==================================

Index

Constants

View Source
const (
	TimeLayout   = "2006-01-02 15:04:05"
	TimeLayout_2 = "20060102150405"
	DateLayout   = "2006-01-02"
)

Variables

This section is empty.

Functions

func AesCBCEncryptToBytes

func AesCBCEncryptToBytes(jsonData []byte, secretKey string) ([]byte, error)

加密后的Bytes数组

func AesCBCEncryptToString

func AesCBCEncryptToString(jsonData []byte, secretKey string) (string, error)

加密后转成Base64字符串

func AesDecryptToBytes

func AesDecryptToBytes(data, secretKey string) ([]byte, error)

解密数据的Bytes数组

func AesDecryptToMap

func AesDecryptToMap(data, secretKey string) (mapData map[string]interface{}, err error)

解密数据到Map集合

func AesDecryptToStruct

func AesDecryptToStruct(data, secretKey string, beanPtr interface{}) (err error)

解密数据到结构体

func BinaryToDecimal added in v1.0.1

func BinaryToDecimal(bit string) (num int)

二进制转10进制

func Float32ToString

func Float32ToString(floatNum float32, prec ...int) (floatStr string)

Float32转字符串

floatNum:float32数字
prec:精度位数(不传则默认float数字精度)

func Float64ToString

func Float64ToString(floatNum float64, prec ...int) (floatStr string)

Float64转字符串

floatNum:float64数字
prec:精度位数(不传则默认float数字精度)

func FormatDate

func FormatDate(dateStr string) (formatDate string)

格式化Date成字符串

格式化前输入样式:2019-01-04T15:40:00Z 或 2019-01-04T15:40:00+08:00
格式化后返回样式:2019-01-04

func FormatDateTime

func FormatDateTime(timeStr string) (formatTime string)

格式化Datetime字符串

格式化前输入样式:2019-01-04T15:40:00Z 或 2019-01-04T15:40:00+08:00
格式化后返回样式:2019-01-04 15:40:00

func GetRandomNumber

func GetRandomNumber(l int) string

随机生成数字字符串

func GetRandomPureString

func GetRandomPureString(l int) string

随机生成纯字符串

func GetRandomString

func GetRandomString(l int) string

随机生成字符串

func Int2String

func Int2String(intNum int) (intStr string)

Int转字符串

intNum:数字字符串

func Int642String

func Int642String(intNum int64) (int64Str string)

Int64转字符串

intNum:数字字符串

func PKCS5Padding

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

加密填充模式(添加补全码) PKCS5Padding 加密时,如果加密bytes的length不是blockSize的整数倍,需要在最后面添加填充byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

解密填充模式(去除补全码) PKCS5UnPadding 解密时,需要在最后面去掉加密时添加的填充byte

func ParseDate

func ParseDate(timeStr string) (date time.Time)

解析日期

日期字符串格式:2006-01-02

func ParseDateTime

func ParseDateTime(timeStr string) (datetime time.Time)

解析时间

时间字符串格式:2006-01-02 15:04:05

func SaveFileToQiniuCloud

func SaveFileToQiniuCloud(pathType, hostName string, formFile *multipart.FileHeader, limitSize int64) (urlPath string, err error)

文件上传

pathType:文件存储路径的名称,例如:photo,video
hostName:七牛云的自定义域名
formFile:接收到的文件
limitSize:文件大小限制(单位Byte)
path:文件路径
err:error

func String2Float32

func String2Float32(floatStr string) (floatNum float32)

字符串转Float32

floatStr:小数点数字的字符串

func String2Float64

func String2Float64(floatStr string) (floatNum float64)

字符串转Float64

floatStr:小数点数字的字符串

func String2Int

func String2Int(intStr string) (intNum int)

字符串转Int

intStr:数字的字符串

func String2Int64

func String2Int64(intStr string) (int64Num int64)

字符串转Int64

intStr:数字的字符串

Types

type Connection

type Connection struct {
	SocketId string
	// contains filtered or unexported fields
}

func InitConnection

func InitConnection(wsConn *websocket.Conn) (conn *Connection, err error)

func (*Connection) Close

func (this *Connection) Close()

func (*Connection) ReadMessage

func (this *Connection) ReadMessage() (data []byte, err error)

func (*Connection) WriteJson

func (this *Connection) WriteJson(data interface{}) (err error)

func (*Connection) WriteMessage

func (this *Connection) WriteMessage(data []byte) (err error)

Jump to

Keyboard shortcuts

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