Compare commits
0
Commits
No files matched your search
@@ -1,103 +0,0 @@
|
|||||||
// Package consistent_hash...
|
|
||||||
//
|
|
||||||
// Description : consistent_hash...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2021-11-21 4:57 下午
|
|
||||||
package consistent_hash
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
// New 获取实例
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:03 下午 2021/11/21
|
|
||||||
func New(replicas int, fn HashFunc) *Consistent {
|
|
||||||
if nil == fn {
|
|
||||||
fn = DefaultHashFunc
|
|
||||||
}
|
|
||||||
return &Consistent{
|
|
||||||
hashFunc: fn,
|
|
||||||
replicas: replicas,
|
|
||||||
keys: make([]int, 0),
|
|
||||||
hashMap: make(map[int]string),
|
|
||||||
lock: &sync.RWMutex{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consistent ...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:00 下午 2021/11/21
|
|
||||||
type Consistent struct {
|
|
||||||
hashFunc HashFunc // 哈希函数
|
|
||||||
replicas int // 虚拟的数量
|
|
||||||
keys []int // 哈希环
|
|
||||||
hashMap map[int]string // 虚拟节点与真实节点的映射表
|
|
||||||
lock *sync.RWMutex // 锁
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add 添加节点
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:10 下午 2021/11/21
|
|
||||||
func (c *Consistent) Add(keyList ...string) {
|
|
||||||
c.lock.Lock()
|
|
||||||
defer c.lock.Unlock()
|
|
||||||
for _, key := range keyList {
|
|
||||||
for i := 0; i < c.replicas; i++ {
|
|
||||||
hash := int(c.hashFunc([]byte(strconv.Itoa(i) + key)))
|
|
||||||
c.keys = append(c.keys, hash)
|
|
||||||
c.hashMap[hash] = key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 哈希值排序
|
|
||||||
sort.Ints(c.keys)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get 获取节点
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:16 下午 2021/11/21
|
|
||||||
func (c *Consistent) Get(key string) string {
|
|
||||||
c.lock.RLock()
|
|
||||||
defer c.lock.Unlock()
|
|
||||||
if len(c.keys) == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
hash := int(c.hashFunc([]byte(key)))
|
|
||||||
// 查找节点索引
|
|
||||||
idx := sort.Search(len(c.keys), func(i int) bool {
|
|
||||||
return c.keys[i] >= hash
|
|
||||||
})
|
|
||||||
return c.hashMap[c.keys[idx%len(c.keys)]]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete 删除一个节点,本质逻辑 : 重建哈希环
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:35 下午 2021/11/21
|
|
||||||
func (c *Consistent) Delete(key string) {
|
|
||||||
c.lock.Lock()
|
|
||||||
defer c.lock.Unlock()
|
|
||||||
tmpKeyList := make([]string, 0)
|
|
||||||
for _, k := range c.hashMap {
|
|
||||||
if k == key {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tmpKeyList = append(tmpKeyList, k)
|
|
||||||
}
|
|
||||||
c.hashMap = make(map[int]string)
|
|
||||||
c.keys = make([]int, 0)
|
|
||||||
c.Add(tmpKeyList...)
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
// Package consistent_hash...
|
|
||||||
//
|
|
||||||
// Description : consistent_hash...
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2021-11-21 4:49 下午
|
|
||||||
package consistent_hash
|
|
||||||
|
|
||||||
import "hash/crc32"
|
|
||||||
|
|
||||||
// HashFunc 哈希函数定义
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 4:50 下午 2021/11/21
|
|
||||||
type HashFunc func(data []byte) uint32
|
|
||||||
|
|
||||||
var (
|
|
||||||
// DefaultHashFunc 默认的哈希函数
|
|
||||||
DefaultHashFunc = crc32.ChecksumIEEE
|
|
||||||
)
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
// Package excel...
|
|
||||||
//
|
|
||||||
// Description : 文件类型转换
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 2021-11-19 5:42 下午
|
|
||||||
package excel
|
|
||||||
|
|
||||||
// NewConvert 获取读取实例
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:45 下午 2021/11/19
|
|
||||||
func NewConvert(fullFilePath string, filePassword string) (*Convert, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
read *Read
|
|
||||||
)
|
|
||||||
if read, err = NewRead(fullFilePath, filePassword); nil != err {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Convert{read: read}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert 格式状态
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:45 下午 2021/11/19
|
|
||||||
type Convert struct {
|
|
||||||
read *Read
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToCSV 转换为CSV
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:46 下午 2021/11/19
|
|
||||||
func (c *Convert) ToCSV() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToJSON 转换为JSON
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:46 下午 2021/11/19
|
|
||||||
func (c *Convert) ToJSON() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToTXT 转换为txt
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 5:47 下午 2021/11/19
|
|
||||||
func (c *Convert) ToTXT(splitChar string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -100,75 +100,3 @@ func (r *Read) GetAllDataToMap(fieldList []string) (map[string][]map[string]stri
|
|||||||
// 格式化数据
|
// 格式化数据
|
||||||
return formatResult, nil
|
return formatResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtractAssignCol 抽取指定的列,并返回list数据, 列的计数从 0 开始
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 4:53 下午 2021/11/19
|
|
||||||
func (r *Read) ExtractAssignCol(colIndexList []int) (map[string][][]string, error) {
|
|
||||||
var (
|
|
||||||
allData map[string][][]string
|
|
||||||
err error
|
|
||||||
formatResult map[string][][]string
|
|
||||||
)
|
|
||||||
if allData, err = r.GetAllData(); nil != err {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
formatResult = make(map[string][][]string)
|
|
||||||
for sheetName, sheetData := range allData {
|
|
||||||
formatResult[sheetName] = make([][]string, 0)
|
|
||||||
for _, lineData := range sheetData {
|
|
||||||
tmpData := make([]string, 0)
|
|
||||||
for _, colIdx := range colIndexList {
|
|
||||||
if len(lineData) <= colIdx {
|
|
||||||
// 索引越界,默认空值
|
|
||||||
tmpData = append(tmpData, "")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tmpData = append(tmpData, lineData[colIdx])
|
|
||||||
}
|
|
||||||
formatResult[sheetName] = append(formatResult[sheetName], tmpData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return formatResult, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtractAssignColToMap 抽取指定的列,并返回map数据
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 4:53 下午 2021/11/19
|
|
||||||
func (r *Read) ExtractAssignColToMap(ruleTable map[int]string) (map[string][]map[string]string, error) {
|
|
||||||
var (
|
|
||||||
allData map[string][][]string
|
|
||||||
err error
|
|
||||||
formatResult map[string][]map[string]string
|
|
||||||
)
|
|
||||||
formatResult = make(map[string][]map[string]string)
|
|
||||||
if allData, err = r.GetAllData(); nil != err {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for sheetName, sheetData := range allData {
|
|
||||||
formatResult[sheetName] = make([]map[string]string, 0)
|
|
||||||
for _, lineData := range sheetData {
|
|
||||||
tmpResult := make(map[string]string)
|
|
||||||
for idx, colData := range lineData {
|
|
||||||
colName, exist := ruleTable[idx]
|
|
||||||
if !exist {
|
|
||||||
// 当前字段不需要提取
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tmpResult[colName] = colData
|
|
||||||
}
|
|
||||||
for _, colName := range ruleTable {
|
|
||||||
if _, exist := tmpResult[colName]; !exist {
|
|
||||||
tmpResult[colName] = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
formatResult[sheetName] = append(formatResult[sheetName], tmpResult)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 格式化数据
|
|
||||||
return formatResult, nil
|
|
||||||
}
|
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
// Package api ...
|
// Package gin ...
|
||||||
//
|
//
|
||||||
// Description : 便捷的相关API处理
|
// Description : 便捷的相关API处理
|
||||||
//
|
//
|
||||||
@@ -23,7 +23,7 @@ type IApi interface {
|
|||||||
GetURI() string
|
GetURI() string
|
||||||
// GetMiddleWareList 使用的中间件列表
|
// GetMiddleWareList 使用的中间件列表
|
||||||
GetMiddleWareList() []gin.HandlerFunc
|
GetMiddleWareList() []gin.HandlerFunc
|
||||||
// GetHandler 处理的handler
|
// 处理的handler
|
||||||
GetHandler() gin.HandlerFunc
|
GetHandler() gin.HandlerFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||