regular update

master 2.0.0
兔子 5 years ago
parent d9e5206ba9
commit 7df7c90d14

@ -8,6 +8,8 @@ import (
"os"
)
// Unzip 读取位于src的zip文件并解压到dst文件夹中
// shell传入当前解压的文件名称
func Unzip(src, dst string, shell func(string)) error {
if !IsFile(src) {
return errors.New(src + " Not Exists")

@ -29,6 +29,7 @@ import (
"time"
)
// StarCrypto 存储了单个校验方法的非编码元数据
type StarCrypto struct {
Sha1 []byte
Sha224 []byte
@ -39,74 +40,58 @@ type StarCrypto struct {
Md5 []byte
}
/*
Base64
*/
func (this StarCrypto) Base64Encode(bstr []byte) string {
// Base64Encode 输出格式化后的Base64字符串
func (starcpto StarCrypto) Base64Encode(bstr []byte) string {
return base64.StdEncoding.EncodeToString(bstr)
}
/*
Base64
*/
func (this StarCrypto) Base64Decode(str string) ([]byte, error) {
// Base64Decode 输出解密前的Base64数据
func (starcpto StarCrypto) Base64Decode(str string) ([]byte, error) {
return base64.StdEncoding.DecodeString(str)
}
/*
MD5
*/
func (this *StarCrypto) MD5(bstr []byte) string {
// MD5 输出MD5校验值
func (starcpto *StarCrypto) MD5(bstr []byte) string {
md5sum := md5.New()
md5sum.Write(bstr)
this.Md5 = md5sum.Sum(nil)
return hex.EncodeToString(this.Md5)
starcpto.Md5 = md5sum.Sum(nil)
return hex.EncodeToString(starcpto.Md5)
}
/*
CRC32
*/
func (this *StarCrypto) CRC32(bstr []byte) string {
// CRC32 输出CRC32校验值
func (starcpto *StarCrypto) CRC32(bstr []byte) string {
crcsum := crc32.NewIEEE()
crcsum.Write(bstr)
this.Crc32 = crcsum.Sum(nil)
return hex.EncodeToString(this.Crc32)
starcpto.Crc32 = crcsum.Sum(nil)
return hex.EncodeToString(starcpto.Crc32)
}
/*
SHA512
*/
func (this *StarCrypto) SHA512(bstr []byte) string {
// SHA512 输出SHA512校验值
func (starcpto *StarCrypto) SHA512(bstr []byte) string {
shasum := sha512.New()
shasum.Write(bstr)
this.Sha512 = shasum.Sum(nil)
return hex.EncodeToString(this.Sha512)
starcpto.Sha512 = shasum.Sum(nil)
return hex.EncodeToString(starcpto.Sha512)
}
/*
SHA256
*/
func (this *StarCrypto) SHA256(bstr []byte) string {
// SHA256 输出SHA256校验值
func (starcpto *StarCrypto) SHA256(bstr []byte) string {
shasum := sha256.New()
shasum.Write(bstr)
this.Sha256 = shasum.Sum(nil)
return hex.EncodeToString(this.Sha256)
starcpto.Sha256 = shasum.Sum(nil)
return hex.EncodeToString(starcpto.Sha256)
}
/*
SHA1
*/
func (this *StarCrypto) SHA1(bstr []byte) string {
// SHA1 输出SHA1校验值
func (starcpto *StarCrypto) SHA1(bstr []byte) string {
shasum := sha1.New()
shasum.Write(bstr)
this.Sha1 = shasum.Sum(nil)
return hex.EncodeToString(this.Sha1)
starcpto.Sha1 = shasum.Sum(nil)
return hex.EncodeToString(starcpto.Sha1)
}
/*
*/
func (this StarCrypto) SumAll(data []byte, method []string) (map[string]string, error) {
// SumAll 可以对同一数据进行多种校验
func (starcpto StarCrypto) SumAll(data []byte, method []string) (map[string]string, error) {
result := make(map[string]string)
methods := make(map[string]hash.Hash)
var iscrc bool
@ -154,17 +139,15 @@ func (this StarCrypto) SumAll(data []byte, method []string) (map[string]string,
return result, nil
}
/*
method,
FileSum("./test.txt","md5",shell(pect float64){fmt.Sprintf("已完成 %f\r",pect)})
*/
func (this StarCrypto) FileSum(filepath, method string, shell func(float64)) (string, error) {
// FileSum 输出文件内容校验值method为单个校验方法,小写
//例FileSum("./test.txt","md5",shell(pect float64){fmt.Sprintf("已完成 %f\r",pect)})
func (starcpto StarCrypto) FileSum(filepath, method string, shell func(float64)) (string, error) {
var sum hash.Hash
var sum32 hash.Hash32
var issum32 bool
var result string
if !Exists(filepath) {
return "", errors.New("File Not Exists!")
return "", errors.New("file not exists")
}
fp, err := os.Open(filepath)
if err != nil {
@ -229,10 +212,8 @@ func (this StarCrypto) FileSum(filepath, method string, shell func(float64)) (st
return result, nil
}
/*
*/
func (this StarCrypto) FileSumAll(filepath string, method []string, shell func(float64)) (map[string]string, error) {
// FileSumAll 可以对同一文件进行多种校验
func (starcpto StarCrypto) FileSumAll(filepath string, method []string, shell func(float64)) (map[string]string, error) {
result := make(map[string]string)
methods := make(map[string]hash.Hash)
var iscrc bool
@ -241,7 +222,7 @@ func (this StarCrypto) FileSumAll(filepath string, method []string, shell func(f
method = []string{"sha512", "sha256", "sha384", "sha224", "sha1", "crc32", "md5"}
}
if !Exists(filepath) {
return result, errors.New("File Not Exists!")
return result, errors.New("file not exists")
}
fp, err := os.Open(filepath)
defer fp.Close()
@ -305,12 +286,13 @@ func (this StarCrypto) FileSumAll(filepath string, method []string, shell func(f
return result, nil
}
func (this StarCrypto) Attach(src, dst, output string) error {
// Attach 合并src与dst文件并输出到output中
func (starcpto StarCrypto) Attach(src, dst, output string) error {
if !Exists(src) {
return errors.New("Source File Not Exists!")
return errors.New("source file not exists")
}
if !Exists(dst) {
return errors.New("Dest File Not Exists!")
return errors.New("dst file not exists")
}
fpsrc, err := os.Open(src)
if err != nil {
@ -344,9 +326,10 @@ func (this StarCrypto) Attach(src, dst, output string) error {
return nil
}
func (this StarCrypto) Detach(src string, bytenum int, dst1, dst2 string) error {
// Detach 按bytenum字节大小分割src文件到dst1与dst2两个新文件中去
func (starcpto StarCrypto) Detach(src string, bytenum int, dst1, dst2 string) error {
if !Exists(src) {
return errors.New("Source File Not Exists!")
return errors.New("source file not exists")
}
fpsrc, err := os.Open(src)
if err != nil {
@ -395,9 +378,10 @@ func (this StarCrypto) Detach(src string, bytenum int, dst1, dst2 string) error
return nil
}
func (this StarCrypto) Base64EncodeFile(src, dst string, shell func(float64)) error {
// Base64EncodeFile 用base64方法编码src文件到dst文件中去shell传入当前进度
func (starcpto StarCrypto) Base64EncodeFile(src, dst string, shell func(float64)) error {
if !Exists(src) {
return errors.New("Source File Not Exists!")
return errors.New("source file not exists")
}
fpsrc, err := os.Open(src)
if err != nil {
@ -429,9 +413,10 @@ func (this StarCrypto) Base64EncodeFile(src, dst string, shell func(float64)) er
return nil
}
func (this StarCrypto) Base64DecodeFile(src, dst string, shell func(float64)) error {
// Base64DecodeFile 用base64方法解码src文件到dst文件中去shell传入当前进度
func (starcpto StarCrypto) Base64DecodeFile(src, dst string, shell func(float64)) error {
if !Exists(src) {
return errors.New("Source File Not Exists!")
return errors.New("source file not exists")
}
fpsrc, err := os.Open(src)
if err != nil {
@ -464,13 +449,12 @@ func (this StarCrypto) Base64DecodeFile(src, dst string, shell func(float64)) er
return nil
}
/*
bynum=true num
bynum=false num
*/
func (this StarCrypto) SplitFile(src, dst string, num int, bynum bool, shell func(float64)) error {
// SplitFile 把src文件按要求分割到dst中去,dst应传入带*号字符串
// 如果bynum=true 则把文件分割成num份
// 如果bynum=false 则把文件按num字节分成多份
func (starcpto StarCrypto) SplitFile(src, dst string, num int, bynum bool, shell func(float64)) error {
if !Exists(src) {
return errors.New("Source File Not Exists!")
return errors.New("source file not exists")
}
fpsrc, err := os.Open(src)
if err != nil {
@ -481,7 +465,7 @@ func (this StarCrypto) SplitFile(src, dst string, num int, bynum bool, shell fun
filebig := float64(stat.Size())
if bynum {
if int(filebig) < num {
return errors.New("File is too small to split")
return errors.New("file is too small to split")
}
}
balance := int(filebig/float64(num)) + 1
@ -526,7 +510,8 @@ func (this StarCrypto) SplitFile(src, dst string, num int, bynum bool, shell fun
return nil
}
func (this StarCrypto) MergeFile(src, dst string, shell func(float64)) error {
// MergeFile 合并src文件到dst文件中去src文件应传入带*号字符串
func (starcpto StarCrypto) MergeFile(src, dst string, shell func(float64)) error {
tmp := strings.Replace(src, "*", "0", -1)
dir, err := ioutil.ReadDir(filepath.Dir(tmp))
if err != nil {
@ -536,7 +521,7 @@ func (this StarCrypto) MergeFile(src, dst string, shell func(float64)) error {
tmp = strings.Replace(base, "*", "(\\d+)", -1)
reg := regexp.MustCompile(tmp)
count := 0
var filebig float64 = 0
var filebig float64
for _, v := range dir {
if reg.MatchString(v.Name()) {
count++
@ -572,10 +557,11 @@ func (this StarCrypto) MergeFile(src, dst string, shell func(float64)) error {
return nil
}
func (this StarCrypto) RSAEncrypt(data, public []byte) ([]byte, error) {
// RSAEncrypt RSA公钥加密
func (starcpto StarCrypto) RSAEncrypt(data, public []byte) ([]byte, error) {
blk, _ := pem.Decode(public)
if blk == nil {
return []byte{}, errors.New("public key error")
return []byte{}, errors.New("public key error")
}
pubkey, err := x509.ParsePKIXPublicKey(blk.Bytes)
if err != nil {
@ -584,7 +570,8 @@ func (this StarCrypto) RSAEncrypt(data, public []byte) ([]byte, error) {
return rsa.EncryptPKCS1v15(rand.Reader, pubkey.(*rsa.PublicKey), data)
}
func (this StarCrypto) RSADecrypt(data, private []byte, password string) ([]byte, error) {
// RSADecrypt RSA私钥解密
func (starcpto StarCrypto) RSADecrypt(data, private []byte, password string) ([]byte, error) {
var prikey *rsa.PrivateKey
var err error
var bytes []byte
@ -612,7 +599,8 @@ func (this StarCrypto) RSADecrypt(data, private []byte, password string) ([]byte
return rsa.DecryptPKCS1v15(rand.Reader, prikey, data)
}
func (this StarCrypto) RSASign(hashdata, private []byte, password string, hashtype crypto.Hash) ([]byte, error) {
// RSASign RSA私钥签名加密
func (starcpto StarCrypto) RSASign(hashdata, private []byte, password string, hashtype crypto.Hash) ([]byte, error) {
var prikey *rsa.PrivateKey
var err error
var bytes []byte
@ -640,7 +628,8 @@ func (this StarCrypto) RSASign(hashdata, private []byte, password string, hashty
return rsa.SignPKCS1v15(rand.Reader, prikey, hashtype, hashdata)
}
func (this StarCrypto) RSAVerify(data, hashdata, public []byte, hashtype crypto.Hash) error {
// RSAVerify RSA公钥签名验证
func (starcpto StarCrypto) RSAVerify(data, hashdata, public []byte, hashtype crypto.Hash) error {
blk, _ := pem.Decode(public)
if blk == nil {
return errors.New("public key error")
@ -652,7 +641,8 @@ func (this StarCrypto) RSAVerify(data, hashdata, public []byte, hashtype crypto.
return rsa.VerifyPKCS1v15(pubkey.(*rsa.PublicKey), hashtype, hashdata, data)
}
func (this StarCrypto) VicqueEncodeV1(srcdata []byte, key string) []byte {
// VicqueEncodeV1 Best
func (starcpto StarCrypto) VicqueEncodeV1(srcdata []byte, key string) []byte {
var keys []int
var saku, piku uint8
data := make([]byte, len(srcdata))
@ -699,7 +689,8 @@ func (this StarCrypto) VicqueEncodeV1(srcdata []byte, key string) []byte {
return data
}
func (this StarCrypto) VicqueDecodeV1(srcdata []byte, key string) []byte {
// VicqueDecodeV1 Best
func (starcpto StarCrypto) VicqueDecodeV1(srcdata []byte, key string) []byte {
var keys []int
var saku, piku int
data := make([]byte, len(srcdata))
@ -746,7 +737,8 @@ func (this StarCrypto) VicqueDecodeV1(srcdata []byte, key string) []byte {
return data[:lens]
}
func (this StarCrypto) VicqueEncodeV1File(src, dst, pwd string, shell func(float64)) error {
// VicqueEncodeV1File best
func (starcpto StarCrypto) VicqueEncodeV1File(src, dst, pwd string, shell func(float64)) error {
fpsrc, err := os.Open(src)
if err != nil {
return err
@ -772,13 +764,14 @@ func (this StarCrypto) VicqueEncodeV1File(src, dst, pwd string, shell func(float
}
sum += n
go shell(float64(sum) / filebig * 100)
data := this.VicqueEncodeV1(buf[0:n], pwd)
data := starcpto.VicqueEncodeV1(buf[0:n], pwd)
fpdst.Write(data)
}
return nil
}
func (this StarCrypto) VicqueDecodeV1File(src, dst, pwd string, shell func(float64)) error {
// VicqueDecodeV1File best
func (starcpto StarCrypto) VicqueDecodeV1File(src, dst, pwd string, shell func(float64)) error {
fpsrc, err := os.Open(src)
if err != nil {
return err
@ -804,12 +797,13 @@ func (this StarCrypto) VicqueDecodeV1File(src, dst, pwd string, shell func(float
}
sum += n
go shell(float64(sum) / filebig * 100)
data := this.VicqueDecodeV1(buf[0:n], pwd)
data := starcpto.VicqueDecodeV1(buf[0:n], pwd)
fpdst.Write(data)
}
return nil
}
// FillWithRandom 随机写filesize大小的文件每次buf大小为bufcap随机bufnum个字符
func FillWithRandom(filepath string, filesize int, bufcap int, bufnum int, shell func(float64)) error {
var buf [][]byte
var buftmp []byte

@ -46,25 +46,76 @@ func (this *StarResultCol) MustBytes() [][]byte {
func (this *StarResultCol) MustBool() []bool {
var res []bool
var tmp bool
for _, v := range this.Result {
res = append(res, v.(bool))
switch vtype := v.(type) {
case nil:
tmp = false
case bool:
tmp = vtype
case float64, float32:
if vtype.(float64) > 0 {
tmp = true
} else {
tmp = false
}
case int, int32, int64:
if vtype.(int) > 0 {
tmp = true
} else {
tmp = false
}
case string:
tmp, _ = strconv.ParseBool(vtype)
default:
tmp, _ = strconv.ParseBool(string(vtype.([]byte)))
}
res = append(res, tmp)
}
return res
}
func (this *StarResultCol) MustFloat32() []float32 {
var res []float32
var tmp float32
for _, v := range this.Result {
res = append(res, v.(float32))
switch vtype := v.(type) {
case nil:
tmp = 0
case float64, float32:
tmp = float32(vtype.(float64))
case string:
tmps, _ := strconv.ParseFloat(vtype, 32)
tmp = float32(tmps)
case int, int32, int64:
tmp = float32(vtype.(int64))
default:
tmp = v.(float32)
}
res = append(res, tmp)
}
return res
}
func (this *StarResultCol) MustFloat64() []float64 {
var res []float64
var tmp float64
for _, v := range this.Result {
res = append(res, v.(float64))
switch vtype := v.(type) {
case nil:
tmp = 0
case float64, float32:
tmp = vtype.(float64)
case string:
tmp, _ = strconv.ParseFloat(vtype, 64)
case int, int32, int64:
tmp = float64(vtype.(int64))
default:
tmp = v.(float64)
}
res = append(res, tmp)
}
return res
}
func (this *StarResultCol) MustString() []string {
var res []string
var tmp string
@ -74,8 +125,20 @@ func (this *StarResultCol) MustString() []string {
tmp = ""
case string:
tmp = vtype
case int64:
tmp = strconv.FormatInt(vtype, 10)
case int32:
tmp = strconv.Itoa(int(vtype))
case bool:
tmp = strconv.FormatBool(vtype)
case float64:
tmp = strconv.FormatFloat(vtype, 'f', 10, 64)
case float32:
tmp = strconv.FormatFloat(float64(vtype), 'f', 10, 32)
case int:
tmp = strconv.Itoa(vtype)
default:
tmp = v.(string)
tmp = string(vtype.([]byte))
}
res = append(res, tmp)
}
@ -84,40 +147,109 @@ func (this *StarResultCol) MustString() []string {
func (this *StarResultCol) MustInt32() []int32 {
var res []int32
var tmp int32
for _, v := range this.Result {
res = append(res, v.(int32))
switch vtype := v.(type) {
case nil:
tmp = 0
case float64, float32:
tmp = int32(vtype.(float64))
case string:
tmps, _ := strconv.ParseInt(vtype, 10, 32)
tmp = int32(tmps)
case int, int32, int64:
tmp = int32(vtype.(int64))
default:
tmp = v.(int32)
}
res = append(res, tmp)
}
return res
}
func (this *StarResultCol) MustInt64() []int64 {
var res []int64
var tmp int64
for _, v := range this.Result {
res = append(res, v.(int64))
switch vtype := v.(type) {
case nil:
tmp = 0
case float64, float32:
tmp = int64(vtype.(float64))
case string:
tmp, _ = strconv.ParseInt(vtype, 10, 64)
case int, int32, int64:
tmp = (vtype.(int64))
default:
tmp = v.(int64)
}
res = append(res, tmp)
}
return res
}
func (this *StarResultCol) MustInt() []int {
var res []int
var tmp int
for _, v := range this.Result {
res = append(res, v.(int))
switch vtype := v.(type) {
case nil:
tmp = 0
case float64, float32:
tmp = int(vtype.(float64))
case string:
tmps, _ := strconv.ParseInt(vtype, 10, 64)
tmp = int(tmps)
case int, int32, int64:
tmp = int(vtype.(int64))
default:
tmp = int(v.(int64))
}
res = append(res, tmp)
}
return res
}
func (this *StarResult) MustInt64(name string) int64 {
var res int64
num, ok := this.columnref[name]
if !ok {
return 0
}
res := this.Result[num].(int64)
tmp := this.Result[num]
switch vtype := tmp.(type) {
case nil:
res = 0
case float64, float32:
res = int64(vtype.(float64))
case string:
res, _ = strconv.ParseInt(vtype, 10, 64)
case int, int32, int64:
res = (vtype.(int64))
default:
res, _ = strconv.ParseInt(string(tmp.([]byte)), 10, 64)
}
return res
}
func (this *StarResult) MustInt32(name string) int32 {
var res int32
num, ok := this.columnref[name]
if !ok {
return 0
}
res := this.Result[num].(int32)
tmp := this.Result[num]
switch vtype := tmp.(type) {
case nil:
res = 0
case float64, float32:
res = int32(vtype.(float64))
case string:
ress, _ := strconv.ParseInt(vtype, 10, 32)
res = int32(ress)
case int, int32, int64:
res = int32(vtype.(int64))
default:
ress, _ := strconv.ParseInt(string(tmp.([]byte)), 10, 32)
res = int32(ress)
}
return res
}
func (this *StarResult) MustString(name string) string {
@ -131,40 +263,123 @@ func (this *StarResult) MustString(name string) string {
res = ""
case string:
res = vtype
case int64:
res = strconv.FormatInt(vtype, 10)
case int32:
res = strconv.Itoa(int(vtype))
case bool:
res = strconv.FormatBool(vtype)
case float64:
res = strconv.FormatFloat(vtype, 'f', 10, 64)
case float32:
res = strconv.FormatFloat(float64(vtype), 'f', 10, 32)
case int:
res = strconv.Itoa(vtype)
default:
res = string(vtype.([]byte))
}
return res
}
func (this *StarResult) MustFloat64(name string) float64 {
var res float64
num, ok := this.columnref[name]
if !ok {
return 0
}
res := this.Result[num].(float64)
switch vtype := this.Result[num].(type) {
case nil:
res = 0
case string:
res, _ = strconv.ParseFloat(vtype, 64)
case float64:
res = vtype
case int, int64, int32, float32:
res = vtype.(float64)
default:
res, _ = strconv.ParseFloat(string(vtype.([]byte)), 64)
}
return res
}
func (this *StarResult) MustFloat32(name string) float32 {
var res float32
num, ok := this.columnref[name]
if !ok {
return 0
}
res := this.Result[num].(float32)
switch vtype := this.Result[num].(type) {
case nil:
res = 0
case string:
tmp, _ := strconv.ParseFloat(vtype, 32)
res = float32(tmp)
case float64:
res = float32(vtype)
case float32:
res = vtype
case int, int64, int32:
res = vtype.(float32)
default:
tmp, _ := strconv.ParseFloat(string(vtype.([]byte)), 32)
res = float32(tmp)
}
return res
}
func (this *StarResult) MustInt(name string) int {
var res int
num, ok := this.columnref[name]
if !ok {
return 0
}
res := this.Result[num].(int)
tmp := this.Result[num]
switch vtype := tmp.(type) {
case nil:
res = 0
case float64, float32:
res = int(vtype.(float64))
case string:
ress, _ := strconv.ParseInt(vtype, 10, 64)
res = int(ress)
case int, int32, int64:
res = int(vtype.(int64))
default:
ress, _ := strconv.ParseInt(string(tmp.([]byte)), 10, 64)
res = int(ress)
}
return res
}
func (this *StarResult) MustBool(name string) bool {
var res bool
num, ok := this.columnref[name]
if !ok {
return false
}
res := this.Result[num].(bool)
tmp := this.Result[num]
switch vtype := tmp.(type) {
case nil:
res = false
case bool:
res = vtype
case float64, float32:
if vtype.(float64) > 0 {
res = true
} else {
res = false
}
case int, int32, int64:
if vtype.(int) > 0 {
res = true
} else {
res = false
}
case string:
res, _ = strconv.ParseBool(vtype)
default:
res, _ = strconv.ParseBool(string(vtype.([]byte)))
}
return res
}
func (this *StarResult) MustBytes(name string) []byte {
@ -212,7 +427,7 @@ func (this *StarRows) Close() error {
func (this *StarRows) parserows() {
this.result = [][]interface{}{}
this.columnref = make(map[string]int)
this.StringResult = []map[string]string{make(map[string]string)}
this.StringResult = []map[string]string{}
this.Columns, _ = this.Rows.Columns()
types, _ := this.Rows.ColumnTypes()
for _, v := range types {

@ -116,6 +116,32 @@ func (this *StarCurl) CurlWithFile(url string, postdata map[string]string, formn
return
}
func (this *StarCurl) CurlWithFileByBytes(url string, postdata map[string]string, formname, fname string, data []byte, savepath string, tofile bool) (result []byte, err error) {
buf := &bytes.Buffer{}
bufwriter := multipart.NewWriter(buf)
if postdata != nil {
for k, v := range postdata {
bufwriter.WriteField(k, v)
}
}
fpdst, err := bufwriter.CreateFormFile(formname, fname)
if err != nil {
return
}
fpdst.Write(data)
this.PostBuffer = buf
this.ReqHeader.Set("Content-Type", "multipart/form-data;boundary="+bufwriter.Boundary())
bufwriter.Close()
if tofile {
err = this.CurlDataToFile(url, []byte{}, "POST", savepath, func(float64) {})
this.ResetReqHeader()
} else {
result, err = this.Curl(url, []byte{}, "POST")
}
this.ResetReqHeader()
return
}
func (this *StarCurl) CurlWithFileByMemory(url string, postdata map[string]string, formname, fpath, savepath string, tofile bool, shell func(float64)) (result []byte, err error) {
buf := &bytes.Buffer{}
bufwriter := multipart.NewWriter(buf)

@ -5,6 +5,9 @@ import (
"errors"
)
/*
SecretKey Key
*/
const SecretKey string = "1996victorique1127B612BTXL"
var header []byte = []byte{11, 27, 19, 96}
@ -59,10 +62,10 @@ type MsgUsed struct {
ID uint16
Msg string
Crc32 string
Ip string
Conn interface{}
}
func (this *StarQueue) ParseMessage(msg []byte, ip string) int {
func (this *StarQueue) ParseMessage(msg []byte, conn interface{}) int {
var buffer bytes.Buffer
buffer.Write(this.UnFinMsg)
buffer.Write(msg)
@ -99,7 +102,7 @@ func (this *StarQueue) ParseMessage(msg []byte, ip string) int {
if this.Encode {
strmsg = Crypto.VicqueDecodeV1(strmsg, SecretKey)
}
msgs := MsgUsed{uint16(uint(id[0])<<8 + uint(id[1])), string(strmsg), string(crc), ip}
msgs := MsgUsed{uint16(uint(id[0])<<8 + uint(id[1])), string(strmsg), string(crc), conn}
this.LastID = int(msgs.ID)
this.MsgPool = append(this.MsgPool, msgs)
}
@ -107,7 +110,7 @@ func (this *StarQueue) ParseMessage(msg []byte, ip string) int {
return -2
}
msg = msg[length+6:]
return this.ParseMessage(msg, ip)
return this.ParseMessage(msg, conn)
}
return -2
}

@ -37,7 +37,7 @@ func NewCircleByteBuffer(len int) *CircleByteBuffer {
return e
}
//Exits返回指定文件夹/文件是否存在
// Exists 返回指定文件夹/文件是否存在
func Exists(filepath string) bool {
_, err := os.Stat(filepath)
if err != nil && os.IsNotExist(err) {
@ -46,7 +46,7 @@ func Exists(filepath string) bool {
return true
}
//IsFile返回给定文件地址是否是一个文件
// IsFile 返回给定文件地址是否是一个文件,
//True为是一个文件,False为不是文件或路径无效
func IsFile(fpath string) bool {
s, err := os.Stat(fpath)
@ -56,7 +56,7 @@ func IsFile(fpath string) bool {
return !s.IsDir()
}
//IsFolder返回给定文件地址是否是一个文件夹
// IsFolder 返回给定文件地址是否是一个文件夹,
//True为是一个文件夹,False为不是文件夹或路径无效
func IsFolder(fpath string) bool {
s, err := os.Stat(fpath)

Loading…
Cancel
Save