Apply .gitignore rules

This commit is contained in:
皮蛋13361098506
2025-01-06 16:21:36 +08:00
parent 1b77f62820
commit ccd2c530cf
580 changed files with 69806 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package fileUtil
import (
"fmt"
"testing"
)
func BenchmarkSaveMessage(b *testing.B) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
bigFileObj, err := NewBigFile(path, 1024*1024*1024)
if err != nil {
b.Errorf("there should no err, but not there is:%s", err)
}
for i := 0; i < b.N; i++ {
bigFileObj.SaveMessage(fmt.Sprintf("line %d", i))
}
}
func TestSaveMessage(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
bigFileObj, err := NewBigFile(path, 1024)
if err != nil {
t.Errorf("there should no err, but not there is:%s", err)
}
for i := 0; i < 100000; i++ {
bigFileObj.SaveMessage(fmt.Sprintf("line %d", i))
}
fileList, err := GetFileList(path)
for _, item := range fileList {
fmt.Printf("file:%s\n", item)
}
}

View File

@@ -0,0 +1,63 @@
package client
import (
"context"
"sync"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var (
// 缓存连接 key:rpc地址 value:连接指针对象
rpcConMap sync.Map
// 连接超时时间
defaultTimeOut = time.Second * 1
)
// GetClientConn
// @description: 获取grpc连接对象
// parameter:
// @rpcAddres:连接地址
// return:
// @*grpc.ClientConn:连接对象
// @error:错误对象
func GetClientConn(rpcAddres string) (*grpc.ClientConn, error) {
// 从缓存获取
if con1, isok := rpcConMap.Load(rpcAddres); isok {
return con1.(*grpc.ClientConn), nil
}
// 构造新对象
//ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(time.Second*1))
var ctx, _ = context.WithTimeout(context.Background(), defaultTimeOut)
con, err := grpc.DialContext(ctx, rpcAddres, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
// 加入缓存
rpcConMap.Store(rpcAddres, con)
return con, nil
}
// ClearClientConn
// @description: 根据连接地址,删除缓存的连接对象
// parameter:
// @rpcAddres:连接地址
// return:
func ClearClientConn(rpcAddres string) {
rpcConMap.Delete(rpcAddres)
}
// SetDefaultTimeOut
// @description: 设置连接的默认超时
// parameter:
// @outTime:超时时间
// return:
func SetDefaultTimeOut(outTime time.Duration) {
defaultTimeOut = outTime
}