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,72 @@
package sqlAsyncMgr
import (
"fmt"
"github.com/jinzhu/gorm"
"goutil/logUtil"
"goutil/stringUtil"
)
type SqlAsyncWorkerPool struct {
// 工作者数量
wcount int32
// 工作者列表
workers []*SqlAsyncWorker
}
// newSqlAsyncWorkerPool 构造同步池
func newSqlAsyncWorkerPool(workerCount int32, _flushCallBack func(*SqlAsyncItemModel), _logAction func(logUtil.LogType, string), _getSyncName func() string, db *gorm.DB) *SqlAsyncWorkerPool {
result := &SqlAsyncWorkerPool{
wcount: workerCount,
workers: make([]*SqlAsyncWorker, workerCount, workerCount),
}
var i int32
for i = 0; i < workerCount; i++ {
newWorker := newSqlAsyncWorker(i, _flushCallBack, _logAction, _getSyncName, db)
result.workers[i] = newWorker
}
return result
}
// Start 启动
func (this *SqlAsyncWorkerPool) Start() {
for _, w := range this.workers {
w.Start()
}
}
// Stop 停止工作
func (this *SqlAsyncWorkerPool) Stop() []*SqlAsyncItemModel {
result := make([]*SqlAsyncItemModel, 0)
for _, w := range this.workers {
if tempList := w.Stop(); tempList != nil {
result = append(result, tempList...)
}
}
return result
}
// GetWork 获取指定work
func (this *SqlAsyncWorkerPool) GetWork(tableName string) (*SqlAsyncWorker, error) {
index := stringUtil.HashCode(tableName) % int(this.wcount)
if index < 0 || index >= int(this.wcount) {
return nil, fmt.Errorf("SqlAsyncWorkerPool中work数量为:%v,不存在id=%v的worker", this.wcount, index)
}
return this.workers[index], nil
}
// GetWaitSyncCount 获取待同步的sql数量
func (this *SqlAsyncWorkerPool) GetWaitSyncCount() int32 {
var count int32
for _, w := range this.workers {
count = count + w.WaitSqlCount()
}
return count
}

View File

@@ -0,0 +1,43 @@
package webServer
import (
"encoding/json"
"fmt"
"goutil/logUtilPlus"
"net/http"
"strconv"
)
// responseResult
// @description: responseResult
// parameter:
// @w: w
// @responseObj: responseObj
// return:
func responseResult(w http.ResponseWriter, responseObj *ResponseObject) {
b, err := json.Marshal(responseObj)
if err != nil {
logUtilPlus.ErrorLog(fmt.Sprintf("序列化输出结果%v出错", responseObj))
return
}
w.Header().Add("Content-Length", strconv.Itoa(len(b)))
w.Write(b)
}
// responseResultByJson
// @description: responseResult
// parameter:
// @w: w
// @responseObj: responseObj
// return:
func responseResultByJson(w http.ResponseWriter, responseObj *ResponseObject) {
b, err := json.Marshal(responseObj)
if err != nil {
logUtilPlus.ErrorLog(fmt.Sprintf("序列化输出结果%v出错", responseObj))
return
}
w.Header().Add("Content-Length", strconv.Itoa(len(b)))
w.Write(b)
}