Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package syncUtil
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// 锁工具类
|
||||
type LockerUtil struct {
|
||||
// 锁集合
|
||||
lockerMap map[string]*Locker
|
||||
|
||||
// 锁对象
|
||||
rwMutex sync.RWMutex
|
||||
}
|
||||
|
||||
// 创建新的锁工具类
|
||||
func NewLockerUtil() *LockerUtil {
|
||||
return &LockerUtil{
|
||||
lockerMap: make(map[string]*Locker, 8),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取锁对象
|
||||
// lockName:锁名
|
||||
// 返回值:
|
||||
// *Locker:锁对象
|
||||
func (this *LockerUtil) GetLock(lockName string) *Locker {
|
||||
var lockerObj *Locker
|
||||
var exists bool
|
||||
|
||||
func() {
|
||||
this.rwMutex.RLock()
|
||||
defer this.rwMutex.RUnlock()
|
||||
lockerObj, exists = this.lockerMap[lockName]
|
||||
}()
|
||||
if exists {
|
||||
return lockerObj
|
||||
}
|
||||
|
||||
this.rwMutex.Lock()
|
||||
defer this.rwMutex.Unlock()
|
||||
|
||||
lockerObj, exists = this.lockerMap[lockName]
|
||||
if !exists {
|
||||
lockerObj = NewLocker()
|
||||
this.lockerMap[lockName] = lockerObj
|
||||
}
|
||||
|
||||
return lockerObj
|
||||
}
|
||||
|
||||
// 释放锁对象
|
||||
// lockName:锁名
|
||||
func (this *LockerUtil) ReleaseLock(lockName string) {
|
||||
this.rwMutex.Lock()
|
||||
defer this.rwMutex.Unlock()
|
||||
delete(this.lockerMap, lockName)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package securityUtil
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHmacSha1(t *testing.T) {
|
||||
source := "oauthConsumerKey=1Nocz0wk0Hi8oGgSosogC4K4k&oauthToken=TOKEN_%2B8vQAR1eoD3ujiGstjzdyakEgbkyvWhfzF1fChQJ46EH07n%2FQvrazkMqy%2BhuprqU&oauthSignatureMethod=HMAC-SHA1&oauthTimestamp=1508486834&oauthNonce=5409983431934290948&oauthVersion=1.0&"
|
||||
key := "f724054cbBF8710D2c3a2500Ec65Fa9F&"
|
||||
sign := "+2zYxghf5BOqAXp/o9yax4TI56c="
|
||||
|
||||
buf, err := HmacSha1(source, key)
|
||||
if err != nil {
|
||||
t.Fatalf("Hmac-SHA1编码错误:%v", err)
|
||||
}
|
||||
|
||||
base64Result := base64.StdEncoding.EncodeToString(buf)
|
||||
if base64Result != sign {
|
||||
t.Fatalf("Hmac-SHA1编码结果不一致")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHmacSha256(t *testing.T) {
|
||||
source := "oauthConsumerKey=1Nocz0wk0Hi8oGgSosogC4K4k&oauthToken=TOKEN_%2B8vQAR1eoD3ujiGstjzdyakEgbkyvWhfzF1fChQJ46EH07n%2FQvrazkMqy%2BhuprqU&oauthSignatureMethod=HMAC-SHA1&oauthTimestamp=1508486834&oauthNonce=5409983431934290948&oauthVersion=1.0&"
|
||||
key := "f724054cbBF8710D2c3a2500Ec65Fa9F&"
|
||||
sign := "6GsbOxY0ldpTqGIdIATUuJceMgCGSwcylODhXxPHZLE="
|
||||
|
||||
buf, err := HmacSha256(source, key)
|
||||
if err != nil {
|
||||
t.Fatalf("Hmac-SHA256编码错误:%v", err)
|
||||
}
|
||||
|
||||
base64Result := base64.StdEncoding.EncodeToString(buf)
|
||||
if base64Result != sign {
|
||||
t.Fatalf("Hmac-SHA256编码结果不一致")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package bytesSendUtil
|
||||
|
||||
/*
|
||||
ensureSendUtil 用于推送数据
|
||||
支持TCP和HTTP两种形式,在发送失败时会缓存数据,并在一定时间间隔后重试
|
||||
|
||||
通过NewTCPSender和NewHTTPSender两个接口分别创建TCP和HTTP模式的EnsureSender
|
||||
|
||||
type EnsureSender interface {
|
||||
// 用于发送数据
|
||||
Write([]byte) error
|
||||
|
||||
// 用于停止发送,此时会自动保存未发送数据
|
||||
Close() error
|
||||
}
|
||||
|
||||
// 创建一个tcp数据发送器
|
||||
// 参数:
|
||||
// _dataFolder 数据存放目录
|
||||
// _address 连接地址
|
||||
func NewTCPSender(_dataFolder, _address string) (EnsureSender, error) {
|
||||
|
||||
|
||||
// 创建一个http数据发送器
|
||||
// 参数:
|
||||
// _dataFolder 数据存放目录
|
||||
// _url 发送地址
|
||||
func NewHTTPSender(_dataFolder, _url string) (EnsureSender, error) {
|
||||
*/
|
||||
@@ -0,0 +1,3 @@
|
||||
package managecenterModel
|
||||
|
||||
// 与ManageCenter共享的模型对象定义
|
||||
Reference in New Issue
Block a user