1
This commit is contained in:
parent
6fd253d455
commit
88b284f7de
29
strutils.go
29
strutils.go
@ -1,13 +1,16 @@
|
|||||||
package q5
|
package q5
|
||||||
|
|
||||||
import "io"
|
import "io"
|
||||||
|
import "strings"
|
||||||
import "crypto/md5"
|
import "crypto/md5"
|
||||||
import "encoding/hex"
|
import "encoding/hex"
|
||||||
import "hash/crc32"
|
import "hash/crc32"
|
||||||
|
|
||||||
func Test()(a string) {
|
const (
|
||||||
return "testb"
|
JSON_NONE = 0
|
||||||
}
|
JSON_ARRAY = iota
|
||||||
|
JSON_OBJECT = iota
|
||||||
|
)
|
||||||
|
|
||||||
func Md5Str(data string) string {
|
func Md5Str(data string) string {
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
@ -22,3 +25,23 @@ func Crc32(data string) uint32 {
|
|||||||
code := ieee.Sum32()
|
code := ieee.Sum32()
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JsonStrType(data string) int32 {
|
||||||
|
arrayIdx := strings.IndexByte(data, '[')
|
||||||
|
objectIdx := strings.IndexByte(data, '{')
|
||||||
|
if arrayIdx < 0 && objectIdx < 0 {
|
||||||
|
return JSON_NONE
|
||||||
|
} else {
|
||||||
|
if arrayIdx < 0 {
|
||||||
|
return JSON_OBJECT
|
||||||
|
}
|
||||||
|
if objectIdx < 0 {
|
||||||
|
return JSON_ARRAY
|
||||||
|
}
|
||||||
|
if arrayIdx < objectIdx {
|
||||||
|
return JSON_ARRAY
|
||||||
|
} else {
|
||||||
|
return JSON_OBJECT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
20
sysutils.go
20
sysutils.go
@ -62,3 +62,23 @@ func TraverseArray(arrayPtr interface{}, callback func(data interface{})) {
|
|||||||
callback(val)
|
callback(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsNumberType(v interface{}) bool {
|
||||||
|
switch reflect.TypeOf(v).Kind() {
|
||||||
|
case
|
||||||
|
reflect.Int,
|
||||||
|
reflect.Int8,
|
||||||
|
reflect.Int16,
|
||||||
|
reflect.Int32,
|
||||||
|
reflect.Int64,
|
||||||
|
reflect.Uint8,
|
||||||
|
reflect.Uint16,
|
||||||
|
reflect.Uint32,
|
||||||
|
reflect.Uint64,
|
||||||
|
reflect.Float32,
|
||||||
|
reflect.Float64:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
7
timer.go
7
timer.go
@ -335,9 +335,14 @@ func (this *Timer) newTimerList() *TimerList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Timer) gcTimerFunc(params *XParams) {
|
func (this *Timer) gcTimerFunc(params *XParams) {
|
||||||
for i := 0; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum && i < 1000; i++ {
|
count := 0
|
||||||
|
for ; !this.freeTimerList.Empty() && this.freeTimerNum > this.cacheTimerNum; {
|
||||||
timerList := this.freeTimerList.FirstEntry().(*TimerList)
|
timerList := this.freeTimerList.FirstEntry().(*TimerList)
|
||||||
timerList.entry.DelInit()
|
timerList.entry.DelInit()
|
||||||
this.freeTimerNum--
|
this.freeTimerNum--
|
||||||
|
count++
|
||||||
|
if count > 1000 {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user