项目基本构成

This commit is contained in:
pixelqm
2019-09-02 00:19:15 +08:00
parent 76d3e97aa8
commit 84a9cbda29
14 changed files with 450 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package tools
import (
"bytes"
"crypto/cipher"
"crypto/des"
)
func padding(src []byte, blocksize int) []byte {
n := len(src)
padnum := blocksize - n%blocksize
pad := bytes.Repeat([]byte{byte(padnum)}, padnum)
dst := append(src, pad...)
return dst
}
func unpadding(src []byte) []byte {
n := len(src)
unpadnum := int(src[n-1])
dst := src[:n-unpadnum]
return dst
}
func EncryptDES(src []byte) []byte {
key := []byte("qimiao66")
block, _ := des.NewCipher(key)
src = padding(src, block.BlockSize())
blockmode := cipher.NewCBCEncrypter(block, key)
blockmode.CryptBlocks(src, src)
return src
}
func DecryptDES(src []byte) []byte {
key := []byte("qimiao66")
block, _ := des.NewCipher(key)
blockmode := cipher.NewCBCDecrypter(block, key)
blockmode.CryptBlocks(src, src)
src = unpadding(src)
return src
}
+34
View File
@@ -0,0 +1,34 @@
// 空值校验工具 仅用于检验空字符串 其余类型请勿使用
package tools
import (
"errors"
"fmt"
"reflect"
)
func HasGap(input interface{}) error {
getType := reflect.TypeOf(input)
fmt.Println("获取类型 :", getType.Name())
getValue := reflect.ValueOf(input)
fmt.Println("所有字段", getValue)
// 获取方法字段
for i := 0; i < getType.NumField(); i++ {
field := getType.Field(i)
value := getValue.Field(i).Interface()
fmt.Printf("%s: %v = %v\n", field.Name, field.Type, value)
if value == "" {
return errors.New(fmt.Sprintf("%s为空", field.Name))
}
}
// 获取方法
// 1. 先获取interface的reflect.Type,然后通过.NumMethod进行遍历
//for i := 0; i < getType.NumMethod(); i++ {
// m := getType.Method(i)
// fmt.Printf("%s: %v\n", m.Name, m.Type)
//}
return nil
}
+12
View File
@@ -0,0 +1,12 @@
package tools
import (
"crypto/md5"
"encoding/hex"
)
func MD5V(str string) string {
h := md5.New()
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}