1
This commit is contained in:
commit
155220a3b2
40
app.go
40
app.go
@ -1,12 +1,13 @@
|
|||||||
package f5
|
package f5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"q5"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"os"
|
|
||||||
"q5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type App interface {
|
type App interface {
|
||||||
@ -75,10 +76,7 @@ func (this *app) init(userApp UserApp) {
|
|||||||
_httpCliMgr = new(HttpCliMgr)
|
_httpCliMgr = new(HttpCliMgr)
|
||||||
_httpCliMgr.init()
|
_httpCliMgr.init()
|
||||||
{
|
{
|
||||||
var tmpNodeId, tmpInstanceId int
|
tmpNodeId, tmpInstanceId := parseArgs()
|
||||||
flag.IntVar(&tmpNodeId, "n", 0, "node id")
|
|
||||||
flag.IntVar(&tmpInstanceId, "i", 0, "instance id")
|
|
||||||
flag.Parse()
|
|
||||||
this.nodeId = int32(tmpNodeId)
|
this.nodeId = int32(tmpNodeId)
|
||||||
this.instanceId = int32(tmpInstanceId)
|
this.instanceId = int32(tmpInstanceId)
|
||||||
}
|
}
|
||||||
@ -256,3 +254,31 @@ func (this *app) installTimer() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseArgs() (int, int) {
|
||||||
|
args := os.Args[1:]
|
||||||
|
if len(args) <= 0 {
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
|
var nodeId, instanceId int
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
arg := args[i]
|
||||||
|
if strings.HasPrefix(arg, "-n") {
|
||||||
|
if len(arg) > 2 {
|
||||||
|
fmt.Sscanf(arg[2:], "%d", &nodeId)
|
||||||
|
} else if i+1 < len(args) {
|
||||||
|
fmt.Sscanf(args[i+1], "%d", &nodeId)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
} else if strings.HasPrefix(arg, "-i") {
|
||||||
|
if len(arg) > 2 {
|
||||||
|
fmt.Sscanf(arg[2:], "%d", &instanceId)
|
||||||
|
} else if i+1 < len(args) {
|
||||||
|
fmt.Sscanf(args[i+1], "%d", &instanceId)
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeId, instanceId
|
||||||
|
}
|
||||||
|
8
constant_unix.go
Normal file
8
constant_unix.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//go:build unix
|
||||||
|
// +build unix
|
||||||
|
|
||||||
|
package f5
|
||||||
|
|
||||||
|
const (
|
||||||
|
SYS_LOG_ROOT = "/data/logs/%s/logs/"
|
||||||
|
)
|
8
constant_windows.go
Normal file
8
constant_windows.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package f5
|
||||||
|
|
||||||
|
const (
|
||||||
|
SYS_LOG_ROOT = "d:/linux_root/data/logs/%s/logs/"
|
||||||
|
)
|
@ -52,7 +52,7 @@ func (this *DataSet) GetByName(name string) *string {
|
|||||||
|
|
||||||
func (this *DataSet) GetByIndex(index int32) *string {
|
func (this *DataSet) GetByIndex(index int32) *string {
|
||||||
this.GetColumns()
|
this.GetColumns()
|
||||||
return this.values[index].(*string);
|
return this.values[index].(*string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDataSet(rows *sql.Rows) *DataSet {
|
func NewDataSet(rows *sql.Rows) *DataSet {
|
||||||
|
60
dbpool.go
60
dbpool.go
@ -1,13 +1,13 @@
|
|||||||
package f5
|
package f5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"q5"
|
"errors"
|
||||||
"time"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"q5"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"errors"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBStyle int32
|
type DBStyle int32
|
||||||
@ -130,13 +130,35 @@ func (this *dbPool) Insert(
|
|||||||
this.internalExec(dataSource, sql, params, cb)
|
this.internalExec(dataSource, sql, params, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *dbPool) Replace(
|
||||||
|
dataSource string,
|
||||||
|
tblName string,
|
||||||
|
fieldsKv [][]string,
|
||||||
|
cb ExecResultCb) {
|
||||||
|
params := []string{}
|
||||||
|
sql := "REPLACE INTO `" + tblName + "` " + this.joinInsertFields(fieldsKv, ¶ms)
|
||||||
|
this.internalExec(dataSource, sql, params, cb)
|
||||||
|
}
|
||||||
|
|
||||||
func (this *dbPool) Upsert(
|
func (this *dbPool) Upsert(
|
||||||
dataSource string,
|
dataSource string,
|
||||||
tblName string,
|
tblName string,
|
||||||
whereKv map[string]string,
|
whereKv [][]string,
|
||||||
updateKv map[string]string,
|
updateKv [][]string,
|
||||||
insertKv map[string]string,
|
insertKv [][]string,
|
||||||
cb ExecResultCb) {
|
cb ExecResultCb) {
|
||||||
|
this.OrmSelectOne(dataSource, tblName, whereKv,
|
||||||
|
func(err error, ds *DataSet) {
|
||||||
|
if err != nil {
|
||||||
|
cb(err, 0, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ds.Next() {
|
||||||
|
this.Update(dataSource, tblName, updateKv, whereKv, cb)
|
||||||
|
} else {
|
||||||
|
this.Insert(dataSource, tblName, insertKv, cb)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *dbPool) PageQuery(
|
func (this *dbPool) PageQuery(
|
||||||
@ -160,16 +182,18 @@ func (this *dbPool) PageQuery(
|
|||||||
}
|
}
|
||||||
this.internalQueryOne(
|
this.internalQueryOne(
|
||||||
dataSource,
|
dataSource,
|
||||||
fmt.Sprintf("SELECT COUNT(*) FROM (%s)", finalySql),
|
fmt.Sprintf("SELECT COUNT(*) FROM (%s) as t", finalySql),
|
||||||
params,
|
params,
|
||||||
func (err error, row *[]*string) {
|
func(err error, rows *DataSet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cb(err, &pagination)
|
cb(err, &pagination)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pagination.Total = q5.ToInt32(*(*row)[0])
|
if rows != nil && rows.Next() {
|
||||||
pagination.TotalPages = int32(math.Ceil(q5.ToFloat64(*(*row)[0]) /
|
pagination.Total = q5.ToInt32(*rows.GetByIndex(0))
|
||||||
|
pagination.TotalPages = int32(math.Ceil(q5.ToFloat64(*rows.GetByIndex(0)) /
|
||||||
float64(pagination.PerPage)))
|
float64(pagination.PerPage)))
|
||||||
|
}
|
||||||
start := pagination.PerPage * (pagination.CurrentPage - 1)
|
start := pagination.PerPage * (pagination.CurrentPage - 1)
|
||||||
limit := pagination.PerPage
|
limit := pagination.PerPage
|
||||||
this.internalQuery(
|
this.internalQuery(
|
||||||
@ -192,14 +216,15 @@ func (this *dbPool) borrowConn(name string) *dataSource {
|
|||||||
for tryCount < 5 {
|
for tryCount < 5 {
|
||||||
{
|
{
|
||||||
this.lock.Lock()
|
this.lock.Lock()
|
||||||
defer this.lock.Unlock()
|
|
||||||
if head, ok := this.dataSourceHash[name]; ok {
|
if head, ok := this.dataSourceHash[name]; ok {
|
||||||
if !head.Empty() {
|
if !head.Empty() {
|
||||||
next := head.Next()
|
next := head.Next()
|
||||||
next.Del()
|
next.Del()
|
||||||
|
this.lock.Unlock()
|
||||||
return next.GetData().(*dataSource)
|
return next.GetData().(*dataSource)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.lock.Unlock()
|
||||||
}
|
}
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
tryCount++
|
tryCount++
|
||||||
@ -271,7 +296,7 @@ func (this *dbPool) joinInsertFields(fieldsKv [][]string, params *[]string) stri
|
|||||||
*params = append(*params, items[1])
|
*params = append(*params, items[1])
|
||||||
}
|
}
|
||||||
sql += ")"
|
sql += ")"
|
||||||
return ""
|
return sql
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *dbPool) internalExec(dataSource string, sql string, params []string,
|
func (this *dbPool) internalExec(dataSource string, sql string, params []string,
|
||||||
@ -334,20 +359,17 @@ func (this *dbPool) internalQueryOne(dataSource string, sql string, params []str
|
|||||||
rows, err := ds.conn.Query(sql, q5.ToInterfaces(params)...)
|
rows, err := ds.conn.Query(sql, q5.ToInterfaces(params)...)
|
||||||
this.returnConn(ds)
|
this.returnConn(ds)
|
||||||
|
|
||||||
values := &[]*string{}
|
var dataSet *DataSet
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dataSet := NewDataSet(rows)
|
dataSet = NewDataSet(rows)
|
||||||
if dataSet.Next() {
|
|
||||||
values = dataSet.GetValues()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
GetSysLog().Info("xxxxxxxxxxxxxxxxxxx")
|
GetSysLog().Info("xxxxxxxxxxxxxxxxxxx")
|
||||||
if this.style == GO_STYLE_DB {
|
if this.style == GO_STYLE_DB {
|
||||||
cb(err, values)
|
cb(err, dataSet)
|
||||||
} else {
|
} else {
|
||||||
_app.RegisterMainThreadCb(
|
_app.RegisterMainThreadCb(
|
||||||
func() {
|
func() {
|
||||||
cb(err, values)
|
cb(err, dataSet)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package f5
|
package f5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"q5"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
|
||||||
"q5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -18,8 +18,9 @@ const (
|
|||||||
LOG_EMERGENCY = iota
|
LOG_EMERGENCY = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
const SYS_LOG_ROOT = "/data/logs/%s/logs/"
|
const (
|
||||||
const SYS_LOG_FILENAME = "log_%d_%s.log"
|
SYS_LOG_FILENAME = "log_%d_%s.log"
|
||||||
|
)
|
||||||
|
|
||||||
type LogMsgNode struct {
|
type LogMsgNode struct {
|
||||||
category int32
|
category int32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user