Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// ************************************
|
||||
// @package: handleMgr
|
||||
// @description: 反射类-响应对象
|
||||
// @author:
|
||||
// @revision history:
|
||||
// @create date: 2022-02-23 16:34:08
|
||||
// ************************************
|
||||
|
||||
package handleMgr
|
||||
|
||||
// ResponseObject 响应对象
|
||||
type ResponseObject struct {
|
||||
// 错误码
|
||||
Code int
|
||||
|
||||
// 响应结果的状态值所对应的描述信息
|
||||
Message string
|
||||
|
||||
// 响应结果的数据
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
// SetResultStatus
|
||||
// @description: 设置响应结果的状态值
|
||||
// parameter:
|
||||
// @receiver r:
|
||||
// @code:响应结果的错误码
|
||||
// @message:响应结果的字符串
|
||||
// return:响应结果对象
|
||||
// @*ResponseObject:
|
||||
func (r *ResponseObject) SetResultStatus(code int, message string) *ResponseObject {
|
||||
r.Code = code
|
||||
r.Message = message
|
||||
return r
|
||||
}
|
||||
|
||||
// SetData
|
||||
// @description: 设置响应结果的状态值
|
||||
// parameter:
|
||||
// @receiver r:
|
||||
// @message:响应结果的字符串
|
||||
// return:响应结果对象
|
||||
// @*ResponseObject:
|
||||
func (r *ResponseObject) SetData(data interface{}) *ResponseObject {
|
||||
r.Data = data
|
||||
return r
|
||||
}
|
||||
|
||||
// GetInitResponseObj
|
||||
// @description: 初始化
|
||||
// parameter:
|
||||
// @moduleName:模块名名称
|
||||
// @methodName:执行方法名称
|
||||
// @parameters:方法参数
|
||||
// @isHaveResult:是否处理返回值
|
||||
// return:
|
||||
// @*ResponseObject:GetInitResponseObj
|
||||
func GetInitResponseObj() *ResponseObject {
|
||||
return &ResponseObject{
|
||||
Message: "",
|
||||
Data: nil,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package lz4Util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
InitString = `{"Code":4,"Message":"IPNotAuthorized","Data":null}`
|
||||
CompressBytes []byte
|
||||
)
|
||||
|
||||
//正确性测试
|
||||
func TestCompress(t *testing.T){
|
||||
s := "hello world"
|
||||
repeatCount:= 1000
|
||||
toCompress := []byte(strings.Repeat(s, repeatCount))
|
||||
compressed,err := Compress(toCompress)
|
||||
if err!=nil{
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("compressed Data:", string(compressed))
|
||||
|
||||
//decompress
|
||||
decompressed,err := Decompress(compressed)
|
||||
if err!=nil{
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if strings.Repeat(s, repeatCount)!=string(decompressed){
|
||||
fmt.Println("有问题")
|
||||
}else{
|
||||
fmt.Println("没问题")
|
||||
}
|
||||
|
||||
fmt.Println("\ndecompressed Data:", string(decompressed))
|
||||
}
|
||||
|
||||
//BenchmarkCompress-12 28647 37948 ns/op
|
||||
func BenchmarkCompress(b *testing.B) {
|
||||
toCompress := []byte(strings.Repeat(InitString, 100))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_,err := Compress(toCompress)
|
||||
if err!=nil{
|
||||
b.Log(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
//BenchmarkDeCompress-12 267382 4127 ns/op
|
||||
func BenchmarkDeCompress(b *testing.B) {
|
||||
toCompress := []byte(strings.Repeat(InitString, 100))
|
||||
compressedData,_ := Compress(toCompress)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_,err := Decompress(compressedData)
|
||||
if err!=nil{
|
||||
b.Log(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
Reference in New Issue
Block a user