init repo

This commit is contained in:
vilet.yy 2021-04-26 23:54:51 +08:00
commit 971b83d480
16 changed files with 692 additions and 0 deletions

33
.gitignore vendored Normal file
View File

@ -0,0 +1,33 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
vendor
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*_test.go
*.prof
*.pprof
*.out
*.log
/bin
cover.out
cover.html

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"go.inferGopath": false
}

106
crypt/aes.go Normal file
View File

@ -0,0 +1,106 @@
/*
* @Date: 2021-03-11 17:03:16
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 22:43:38
* @FilePath: /yolk/crypt/aes.go
*/
package crypt
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"fmt"
)
/*
* AES,即高级加密标准Advanced Encryption Standard,是一个对称分组密码算法,旨在取代DES成为广泛使用的标准.
* AES中常见的有三种解决方案,分别为AES-128,AES-192和AES-256. AES加密过程涉及到4种操作字节替代SubBytes
* ,行移位ShiftRows,列混淆MixColumns和轮密钥加AddRoundKey.解密过程分别为对应的逆操作.由于每一步
* 操作都是可逆的,按照相反的顺序进行解密即可恢复明文.加解密中每轮的密钥分别由初始密钥扩展得到.算法中16字节的明文,
* 密文和轮密钥都以一个4x4的矩阵表示. AES 有五种加密模式电码本模式Electronic Codebook Book (ECB),
* 码分组链接模式Cipher Block Chaining (CBC),计算器模式Counter (CTR),密码反馈模式Cipher Feed
* Back (CFB)和输出反馈模式Output FeedBack (OFB)
*/
var aesKey = "123456781234567812345678"
type AesCrypt struct {
Key string
}
func NewAesCrypt(key ...string) *AesCrypt {
if len(key) > 0 {
aesKey = key[0]
}
return &AesCrypt{
Key: aesKey,
}
}
//AES加密
func (crypt *AesCrypt) Encrypt(orig string) string {
// 转成字节数组
origData := []byte(orig)
k := []byte(crypt.Key)
// 分组密钥
block, err := aes.NewCipher(k)
if err != nil {
panic(fmt.Sprintf("key 长度必须 16/24/32长度%s", err.Error()))
}
// 获取密钥块的长度
blockSize := block.BlockSize()
// 补全码
origData = PKCS7Padding(origData, blockSize)
// 加密模式
blockMode := cipher.NewCBCEncrypter(block, k[:blockSize])
// 创建数组
cryted := make([]byte, len(origData))
// 加密
blockMode.CryptBlocks(cryted, origData)
// 使用RawURLEncoding 不要使用StdEncoding
// 不要使用StdEncoding 放在url参数中会导致错误
return base64.RawURLEncoding.EncodeToString(cryted)
}
//AES解密
func (crypt *AesCrypt) Decrypt(cryted string) string {
// 使用RawURLEncoding 不要使用StdEncoding
// 不要使用StdEncoding 放在url参数中回导致错误
crytedByte, _ := base64.RawURLEncoding.DecodeString(cryted)
k := []byte(crypt.Key)
// 分组密钥
block, err := aes.NewCipher(k)
if err != nil {
panic(fmt.Sprintf("key 长度必须 16/24/32长度%s", err.Error()))
}
// 获取密钥块的长度
blockSize := block.BlockSize()
// 加密模式
blockMode := cipher.NewCBCDecrypter(block, k[:blockSize])
// 创建数组
orig := make([]byte, len(crytedByte))
// 解密
blockMode.CryptBlocks(orig, crytedByte)
// 去补全码
orig = PKCS7UnPadding(orig)
return string(orig)
}
//补码
func PKCS7Padding(ciphertext []byte, blocksize int) []byte {
padding := blocksize - len(ciphertext)%blocksize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(ciphertext, padtext...)
}
//去码
func PKCS7UnPadding(origData []byte) []byte {
length := len(origData)
unpadding := int(origData[length-1])
return origData[:(length - unpadding)]
}

42
crypt/base64.go Normal file
View File

@ -0,0 +1,42 @@
/*
* @Date: 2021-03-11 18:14:52
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 22:40:12
* @FilePath: /yolk/crypt/base64.go
*/
package crypt
import (
"encoding/base64"
)
/*
* Base64是一种任意二进制到文本字符串的编码方法,常用于在URL,Cookie,网页中传输少量二进制数据.
* 首先使用Base64编码需要一个含有64个字符的表,这个表由大小写字母,数字,+/组成.采用Base64编
* 码处理数据时,会把每三个字节共24位作为一个处理单元,再分为四组,每组6位,查表后获得相应的字符即
* 编码后的字符串.编码后的字符串长32位,这样,经Base64编码后,原字符串增长1/3.如果要编码的数据不
* 是3的倍数,最后会剩下一到两个字节,Base64编码中会采用\x00在处理单元后补全,编码后的字符串最后
* 会加上一到两个 = 表示补了几个字节.
*/
var coderTable = "IJjkKLMNO567PQX12RVW3YZaDEFGbcdefghiABCHlSTUmnopqrxyz04stuvw89+/"
type Base64Crypt struct {
Coder *base64.Encoding
}
func NewBase64Crpyt(table ...string) *Base64Crypt {
if len(table) > 0 {
coderTable = table[0]
}
return &Base64Crypt{
Coder: base64.NewEncoding(coderTable),
}
}
func (crypt *Base64Crypt) Base64Encode(src []byte) []byte { //编码
return []byte(crypt.Coder.EncodeToString(src))
}
func (crypt *Base64Crypt) Base64Decode(src []byte) ([]byte, error) { //解码
return crypt.Coder.DecodeString(string(src))
}

97
crypt/des.go Normal file
View File

@ -0,0 +1,97 @@
/*
* @Date: 2021-03-11 17:25:13
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 23:17:26
* @FilePath: /yolk/crypt/des.go
*/
package crypt
import (
"bytes"
"crypto/des"
"encoding/hex"
"errors"
)
/*
* DES是一种对称加密算法,又称为美国数据加密标准.DES加密时以64位分组对数据进行加密,加密和解密都使用的是同一个长度为64位的密钥,
* 实际上只用到了其中的56位,密钥中的第8,1664位用来作奇偶校验.DES有ECB电子密码本和CBC加密块等加密模式. DES算法的安
* 全性很高,目前除了穷举搜索破解外, 尚无更好的的办法来破解.其密钥长度越长,破解难度就越大. 填充和去填充函数.
*/
var desKey = []byte("2fa6c1e9")
type DesCrypt struct {
Key []byte
}
func NewDesCrypt(key ...[]byte) *DesCrypt {
if len(key) > 0 {
desKey = key[0]
}
return &DesCrypt{
Key: desKey,
}
}
// Des加密
func (crypt *DesCrypt) Encrypt(text string) (string, error) {
src := []byte(text)
block, err := des.NewCipher(crypt.Key)
if err != nil {
return "", err
}
bs := block.BlockSize()
src = ZeroPadding(src, bs)
if len(src)%bs != 0 {
return "", errors.New("Need a multiple of the blocksize")
}
out := make([]byte, len(src))
dst := out
for len(src) > 0 {
block.Encrypt(dst, src[:bs])
src = src[bs:]
dst = dst[bs:]
}
return hex.EncodeToString(out), nil
}
// Des解密
func (crypt *DesCrypt) Decrypt(decrypted string) (string, error) {
src, err := hex.DecodeString(decrypted)
if err != nil {
return "", err
}
block, err := des.NewCipher(crypt.Key)
if err != nil {
return "", err
}
out := make([]byte, len(src))
dst := out
bs := block.BlockSize()
if len(src)%bs != 0 {
return "", errors.New("crypto/cipher: input not full blocks")
}
for len(src) > 0 {
block.Decrypt(dst, src[:bs])
src = src[bs:]
dst = dst[bs:]
}
out = ZeroUnPadding(out)
return string(out), nil
}
func ZeroPadding(ciphertext []byte, blockSize int) []byte {
padding := blockSize - len(ciphertext)%blockSize
padtext := bytes.Repeat([]byte{0}, padding)
return append(ciphertext, padtext...)
}
func ZeroUnPadding(origData []byte) []byte {
return bytes.TrimFunc(origData,
func(r rune) bool {
return r == rune(0)
})
}

47
crypt/key_pairs.go Normal file
View File

@ -0,0 +1,47 @@
/*
* @Date: 2021-03-11 18:02:34
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 23:00:24
* @FilePath: /yolk/crypt/key_pairs.go
*/
package crypt
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"encoding/pem"
"fmt"
"os"
)
// ecdsaCmd represents the doc command
func KeyPairs(keyName string) {
//elliptic.P256(),elliptic.P384(),elliptic.P521()
privateKey, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
if err != nil {
panic(fmt.Sprintf("Genera KeyPairs Error: %v", err))
}
x509Encoded, _ := x509.MarshalECPrivateKey(privateKey)
privateBs := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: x509Encoded})
privateFile, err := os.Create(keyName + ".private.pem")
if err != nil {
panic(fmt.Sprintf("Genera KeyPairs Error: %v", err))
}
_, err = privateFile.Write(privateBs)
if err != nil {
panic(fmt.Sprintf("Genera KeyPairs Error: %v", err))
}
x509EncodedPub, _ := x509.MarshalPKIXPublicKey(privateKey.Public())
publicBs := pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: x509EncodedPub})
publicKeyFile, err := os.Create(keyName + ".public.pem")
if err != nil {
panic(fmt.Sprintf("Genera KeyPairs Error: %v", err))
}
_, err = publicKeyFile.Write(publicBs)
if err != nil {
panic(fmt.Sprintf("Genera KeyPairs Error: %v", err))
}
}

34
crypt/md5.go Normal file
View File

@ -0,0 +1,34 @@
/*
* @Date: 2021-03-11 18:06:18
* @LastEditors: viletyy
* @LastEditTime: 2021-03-11 18:18:08
* @FilePath: /hello/utils/crypt/md5.go
*/
package crypt
import (
"crypto/md5"
"encoding/hex"
"strings"
)
/*
* MD5的全称是Message-DigestAlgorithm 5,它可以把一个任意长度的字节数组转换成一个定长的整数,并且这种转换是不可
* 逆的.对于任意长度的数据,转换后的MD5值长度是固定的,而且MD5的转换操作很容易,只要原数据有一点点改动,转换后结果就
* 会有很大的差异.正是由于MD5算法的这些特性,它经常用于对于一段信息产生信息摘要,以防止其被篡改.其还广泛就于操作系
* 统的登录过程中的安全验证,比如Unix操作系统的密码就是经过MD5加密后存储到文件系统中,当用户登录时输入密码后, 对用
* 户输入的数据经过MD5加密后与原来存储的密文信息比对,如果相同说明密码正确,否则输入的密码就是错误的. MD5以512位为
* 一个计算单位对数据进行分组,每一分组又被划分为16个32位的小组,经过一系列处理后,输出4个32位的小组,最后组成一个128
* 位的哈希值.对处理的数据进行512求余得到N和一个余数,如果余数不为448,填充1和若干个0直到448位为止,最后再加上一个64
* 位用来保存数据的长度,这样经过预处理后,数据变成N+1x 512. 加密.Encode 函数用来加密数据,Check函数传入一个
* 未加密的字符串和与加密后的数据,进行对比,如果正确就返回true.
*/
func Md5Check(content, encrypted string) bool {
return strings.EqualFold(Md5Encode(content), encrypted)
}
func Md5Encode(data string) string {
h := md5.New()
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}

99
crypt/rsa.go Normal file
View File

@ -0,0 +1,99 @@
/*
* @Date: 2021-03-11 17:51:14
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 23:11:30
* @FilePath: /yolk/crypt/rsa.go
*/
package crypt
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
)
// 私钥生成
//openssl genrsa -out rsa_private_key.pem 1024
var privateKey = []byte(`
-----BEGIN RSA PRIVATE KEY-----
MIICXwIBAAKBgQC1mv515+z3BQYim0nKZPrYm94fPoX0Ew/AJggSdnA2shRsJdMk
AWretmVVej0AH3mBJ1+6tBXXB8+d+7ffNeHWJYrzoh7gPompQWEIvnArcwnhvTA+
8xtdd82GWDKC46pNSqhUGEG/oEqq8Y7C3YoReppJWX7M7xut+YHI+m1hhwIDAQAB
AoGBAIO5WLjM8OR7kGepm2xislBLPmILR74x1UraSyCZJ+uEX6vSA8QqAwpn4jiN
4ZElQ0ya8qTJ2s2NrNo6qrQMsTEaLKYrombAkZbghRYjeAhVCAnIFdchLpV/BG7n
NqxdzV8p1iZeK7qGQm9SWWzS60eO+5RCeUWRB9l3VKai242BAkEA32iXN6bZAIeW
wUIr5GiOV8l6Puw8Or/nRMISHqo4qpbZu2btUTmOuHbLNMo+vVIxCtem2QYGsgMj
9P44fVwJtQJBANAZObuBUkbsqbX/CA+ikDKDtN6wET6S1KaKTU0P5XhxIWeBE8at
EQNqzqaTZ+IMeohjDxTzFlFb3VhHFi2cU8sCQQDM5tSqijDFN5ahMdun5e2HvpaM
V4b2K0Ql4AlWbrECZNDV/JT0xmGL9ghyJnxcj6HDW/7/VXOWmSLFdNTCxUNxAkEA
i8hGBXOKxuV14jBbQ9VYsvXRarwt+TA781p3Lkp9Q3gKjjIgDJZ4FSmLgk0FvMvR
CwgvO01GMoRYnFGzzhNyHQJBALy1gjYLIwHwZYb5ul0s1KJGbY+Tw1qabyQ6lm6A
n5sq4iney5DPUjKcxcP17XvlD9lx7GOS8/ZVWx4krPkydOg=
-----END RSA PRIVATE KEY-----
`)
// 公钥: 根据私钥生成
//openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
var publicKey = []byte(`
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1mv515+z3BQYim0nKZPrYm94f
PoX0Ew/AJggSdnA2shRsJdMkAWretmVVej0AH3mBJ1+6tBXXB8+d+7ffNeHWJYrz
oh7gPompQWEIvnArcwnhvTA+8xtdd82GWDKC46pNSqhUGEG/oEqq8Y7C3YoReppJ
WX7M7xut+YHI+m1hhwIDAQAB
-----END PUBLIC KEY-----
`)
type RsaCrypt struct {
PublicKey []byte
PrivateKey []byte
}
func NewRsaCrypt(key ...[][]byte) *RsaCrypt {
if len(key) > 0 {
if len(key[0]) > 0 {
privateKey = key[0][0]
publicKey = key[0][1]
}
}
return &RsaCrypt{
PrivateKey: privateKey,
PublicKey: publicKey,
}
}
// 加密
// 这里最后的结果需要用 base64.StdEncoding.EncodeToString(data)
func (crypt *RsaCrypt) Encrypt(origData []byte) ([]byte, error) {
//解密pem格式的公钥
block, _ := pem.Decode(crypt.PublicKey)
if block == nil {
return nil, errors.New("public key error")
}
// 解析公钥
pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return nil, err
}
// 类型断言
pub := pubInterface.(*rsa.PublicKey)
//加密
return rsa.EncryptPKCS1v15(rand.Reader, pub, origData)
}
// 解密
func (crypt *RsaCrypt) Decrypt(ciphertext []byte) ([]byte, error) {
//解密
block, _ := pem.Decode(crypt.PrivateKey)
if block == nil {
return nil, errors.New("private key error!")
}
//解析PKCS1格式的私钥
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {
return nil, err
}
// 解密
return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)
}

15
crypt/rsa_private_key.pem Normal file
View File

@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDI1pnhTbTR/JX/OQG1Wce382owRPLMZtY9Oh8IPaogCOBcOuli
wTU1kEJUvSwxhTxM2h4O2OPY88G8flnD675ufuf+xvho39SbpXP+Sdweox8LhUoO
ExIiU5gNH9EtRInRXnT3ZnzG4wxclHH12J4Zhp/JYz/Yf4SmkxAYgfvXBwIDAQAB
AoGAXDFGygnlq08Le/ErO5hO+b4fTLEZ04KRbeG0RRApfDMW6r+QSujuB/yEtmlw
U/sZRx4JFj+xt/GNSX2mry0UaMwjDLEYjQB6gjm8hy5G38unAbmJOYa7bnXeyY+5
kRCWl2PrycJcOG1ywY85RO+u0xGQR0KY0qOURxqk4XoN4gECQQDuNP4ffcFY5Uka
BETaOXmfgy12iwszI5s9fBZO2jCfVhrlyQbcW2RJmaUWGfE5SoYfNSas6VvAT4QG
fTm5ii/HAkEA19cKsbbIIHNVO0mYDhCak7O3YsLMJFcMXkJdJbFfVla884WZNrhs
FPHs4eGHw0XND6NWAAeK5z7Y1PkEcCeewQJBAMHcLtTCK5CFSbD6uG5BSFIhF+bZ
0guUdsrbKeySde+2y70mlYbQehXMDSanhkHx/KV5RDiE0j74d6IwV8JATBECQBWb
qK1r8BMXmMPLtVZLIT6CMmzHtao5sLpLCIo6fKHnIxl6GYGZ6vAZ3C4s5uuMtF/J
aVWta6GE8C46E9CqlsECQQChQxPp3nPMGYS2dD2bSlWe5Wia88A03SsCf3vm/pyJ
yxfKx3wij345/HdNy/0N+/6OxlQ2PYA/KtxYS2fdzYLQ
-----END RSA PRIVATE KEY-----

6
crypt/rsa_public_key.pem Normal file
View File

@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI1pnhTbTR/JX/OQG1Wce382ow
RPLMZtY9Oh8IPaogCOBcOuliwTU1kEJUvSwxhTxM2h4O2OPY88G8flnD675ufuf+
xvho39SbpXP+Sdweox8LhUoOExIiU5gNH9EtRInRXnT3ZnzG4wxclHH12J4Zhp/J
Yz/Yf4SmkxAYgfvXBwIDAQAB
-----END PUBLIC KEY-----

23
crypt/sha1.go Normal file
View File

@ -0,0 +1,23 @@
/*
* @Date: 2021-03-11 18:07:34
* @LastEditors: viletyy
* @LastEditTime: 2021-03-11 18:11:49
* @FilePath: /hello/utils/crypt/sha1.go
*/
package crypt
import (
"crypto/sha1"
"encoding/hex"
"strings"
)
func Sha1Check(content, encrpyted string) bool {
return strings.EqualFold(Sha1Encode(content), encrpyted)
}
func Sha1Encode(data string) string {
h := sha1.New()
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}

24
crypt/sha256.go Normal file
View File

@ -0,0 +1,24 @@
/*
* @Date: 2021-03-11 18:12:11
* @LastEditors: viletyy
* @LastEditTime: 2021-03-11 18:14:43
* @FilePath: /hello/utils/crypt/sha256.go
*/
package crypt
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"strings"
)
func Sha256Check(content, secret, encrypted string) bool {
return strings.EqualFold(Sha256Encode(content, secret), encrypted)
}
func Sha256Encode(data, secret string) string {
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}

42
directory.go Normal file
View File

@ -0,0 +1,42 @@
/*
* @Date: 2021-03-22 10:45:37
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 21:15:38
* @FilePath: /yolk/directory.go
*/
package yolk
import (
"fmt"
"os"
"go.uber.org/zap"
)
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func CreateDir(dirs ...string) (err error) {
for _, v := range dirs {
exist, err := PathExists(v)
if err != nil {
return err
}
if !exist {
fmt.Println("create directory" + v)
err = os.MkdirAll(v, os.ModePerm)
if err != nil {
fmt.Println("create directory"+v, zap.Any(" error:", err))
}
}
}
return err
}

15
go.mod Normal file
View File

@ -0,0 +1,15 @@
module github.com/viletyy/yolk
go 1.15
require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.6.1 // indirect
go.uber.org/zap v1.16.0
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
)

83
go.sum Normal file
View File

@ -0,0 +1,83 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 h1:2M3HP5CCK1Si9FQhwnzYhXdG6DXeebvUHFpre8QvbyI=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.5 h1:nI5egYTGJakVyOryqLs1cQO5dO0ksin5XXs2pspk75k=
honnef.co/go/tools v0.0.1-2020.1.5/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=

23
helper.go Normal file
View File

@ -0,0 +1,23 @@
/*
* @Date: 2021-03-12 17:37:03
* @LastEditors: viletyy
* @LastEditTime: 2021-04-26 21:18:37
* @FilePath: /yolk/helper.go
*/
package yolk
import "strconv"
func ToString(i interface{}) string {
switch i.(type) {
case string:
return i.(string)
case int:
return strconv.Itoa(i.(int))
case int64:
return strconv.FormatInt(i.(int64), 10)
case uint:
return strconv.Itoa(int(i.(uint)))
}
return ""
}