monchickey

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

gomonchickey - go语言实现的工具库

go version: 1.13
example code
package main

import (
    "fmt"
    "time"

    "github.com/zengzhiying/gomonchickey"
)

func main() {
    nowTimestamp := time.Now().Unix()
    nowTimeStr := monchickey.TimestampToString(nowTimestamp, "2006-01-02 15:04:05")
    fmt.Println(nowTimeStr)

    numSeq := []uint8{72, 101, 108, 108, 111, 32, 109, 111, 110, 99, 104, 105, 99, 107, 101, 121, 33}
    raw := monchickey.Uint8ToBytes(numSeq)
    fmt.Println(string(raw))

    geoHash, err := monchickey.GeohashEncode(113.56291, 36.9271, 12)
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println("(113.56291, 36.9271) geohash Encode:", geoHash)
    }
}

output:
2019-11-06 21:13:17
Hello monchickey! (113.56291, 36.9271) geohash Encode: ww8f04mgzw75

Documentation

Index

Constants

View Source
const (
	MAX_LON = 180
	MIN_LON = -180
	MAX_LAT = 90
	MIN_LAT = -90
)

经纬度范围

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(encodedData string) ([]byte, error)

base64解码

func Base64Encode

func Base64Encode(data []byte) string

base64编码

func ByteToFloat16

func ByteToFloat16(high, low byte) float64

两个字节转float16的数值表示 返回值: float64 对应float16表示的浮点数

func BytesToUint16Bigend

func BytesToUint16Bigend(bs []byte) ([]uint16, error)

解包二进制数组为uint16切片[大端]

func BytesToUint16Smallend

func BytesToUint16Smallend(bs []byte) ([]uint16, error)

解包二进制数组为uint16切片[小端]

func EncodeToHex

func EncodeToHex(src []byte) string

编码二进制为hex格式的字符串

func GeohashDecode

func GeohashDecode(encoded string) (longitude, latitude float64, err error)

geohash解码函数 encoded: hash编码后的字符串, 长度: 1-12 returns: 经度, 纬度, 错误信息

func GeohashEncode

func GeohashEncode(longitude, latitude float64, precision int) (string, error)

geohash编码函数 longitude: 经度 latitude: 纬度 precision: 精度, 范围: 1-12 returns: geohash编码后的字符串, 错误信息

func GetFileModifyTime

func GetFileModifyTime(filename string) string

获得文件的修改时间, 返回字符串示例: 2019-01-01 11:11:00 当文件不存在或出错时返回空字符串

func GetUint32Bit

func GetUint32Bit(num uint32, index uint8) (value uint8, err error)

获取uint32指定位的值, index从高位到低位: 1 - 32

func GetUint64Bit

func GetUint64Bit(num uint64, index uint8) (value uint8, err error)

获取uint64指定位的值 index从高位到低位依次为: 1 - 64

func GetYamlConfig

func GetYamlConfig(configFile string, configs interface{}) error

加载yaml配置文件 configFile: 配置文件路径; configs: 结构体指针, 注意是传地址

func GobDeserialize

func GobDeserialize(filePath string, content interface{}) error

将gob内容反序列化为数据 filePath: 文件绝对路径 content: 接收返回内容的指针

func GobSerialize

func GobSerialize(filePath string, content interface{}) error

将指定内容以gob方式序列化到文件 特殊数据类型需要提前注册 filePath: 文件绝对路径

func HexDecode

func HexDecode(s string) ([]byte, error)

解码hex为二进制数组

func IntArrayContain

func IntArrayContain(arr []int, v int) bool

判断整数切片中是否包含元素

func MD5Digest

func MD5Digest(data []byte) []byte

md5摘要计算, 返回为md5后的二进制, 长度为16

func MD5HexDigest

func MD5HexDigest(data []byte) string

md5摘要计算, 返回md5后的16进制字符串, 长度为32

func PathIsDir

func PathIsDir(path string) bool

判断path是不是目录

func PathIsExist

func PathIsExist(path string) bool

判断文件或目录是不是存在

func PathIsFile

func PathIsFile(path string) bool

判断path是不是文件

func SetUint32Bit

func SetUint32Bit(num *uint32, index, value uint8) (err error)

设置uint32指定位的值 index是从高位到低位, 范围: 1 - 32

func SetUint64Bit

func SetUint64Bit(num *uint64, index, value uint8) (err error)

设置uint64指定位的值 index是从高位到低位, index依次为: 1 - 64

func StringToTimestamp

func StringToTimestamp(timeAsStr, timeFormat string) (int64, error)

字符串格式的时间转时间戳, 注意: 按照本地时区进行转换 返回: 转换成功error为nil, 返回时间戳, 单位为s; 转换失败error不为nil

func TimeZoneStringToTimestamp

func TimeZoneStringToTimestamp(timeAsStr, timeFormat, timeZone string) (int64, error)

按照指定的时区转换时间戳, 比如: UTC - UTC时间, Asia/Shanghai - 东八区时间

func TimestampToString

func TimestampToString(timestamp int64, timeFormat string) string

unix时间戳转时间字符串 timestamp: 时间戳, 单位: s timeFormat: 格式化方式, 例如: "2006-01-02 15:04:05"

func Uint8ToBytes

func Uint8ToBytes(seq []uint8) []byte

打包uint8序列为二进制序列

func Uint8Transform

func Uint8Transform(value, defaultValue int) int

校验int是否在uint8范围内 校验通过返回value, 否则返回defaultValue默认值

func Uint16ToBytesBigend

func Uint16ToBytesBigend(seq []uint16) []byte

打包uint16序列为二进制序列[大端]

func Uint16ToBytesSmallend

func Uint16ToBytesSmallend(seq []uint16) []byte

打包uint16序列为二进制序列[小端]

func Uint16Transform

func Uint16Transform(value, defaultValue int) int

校验int是否在uint16范围内 校验通过返回value, 否则返回defaultValue默认值

func XXHashSum64

func XXHashSum64(data []byte) uint64

xxhash 64 计算, 返回uint64的整数

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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