This commit is contained in:
殷勇 2023-10-25 15:46:41 +08:00
parent ef6a02719b
commit 50cb269954
8 changed files with 44 additions and 39 deletions

View File

@ -1,9 +1,9 @@
package q5
import (
"errors"
"strconv"
"strings"
"errors"
)
// ToInt converts a value to an integer.
@ -11,6 +11,11 @@ func ToInt32[T string | int | int32 | int64 | float32 | float64](value T) int32
return int32(ToInt64(value))
}
// ToInt converts a value to an integer.
func ToInt[T string | int32 | int64 | float32 | float64](value T) int {
return int(ToInt64(value))
}
// ToInt64 converts a value to an int64.
func ToInt64[T string | int | int32 | int64 | float32 | float64](value T) int64 {
var x interface{} = value
@ -80,7 +85,7 @@ func ToString[T string | int | int32 | int64 | float32 | float64](value T) strin
return ""
}
func ToInt64Ex(x interface{}) (int64, error) {
func ToInt64Ex(x interface{}) (int64, error) {
switch i := x.(type) {
case int:
return int64(i), nil
@ -140,7 +145,7 @@ func ToStringEx(x interface{}) (string, error) {
}
func DuckToSimple[T string | int | int32 | int64 | float32 | float64](
d interface{}, s *T) bool {
d interface{}, s *T) bool {
var sx interface{} = s
switch sv := sx.(type) {
case *int:

View File

@ -1,16 +1,16 @@
package q5
import (
"errors"
"io/ioutil"
"net/http"
net_url "net/url"
"io/ioutil"
"errors"
//"strings"
)
const (
HTTP_OPT_ADD_HEADER = iota
HTTP_OPT_SET_PROXY = iota
HTTP_OPT_SET_PROXY = iota
)
func internalSetOpt(client *http.Client, request *http.Request, opt int32,
@ -45,7 +45,7 @@ func HttpGetEx(url string, params map[string]string,
panic("http.NewRequest error")
}
if initFunc != nil {
initFunc(func (opt int32, key string, val string) {
initFunc(func(opt int32, key string, val string) {
internalSetOpt(client, request, opt, key, val)
})
}

View File

@ -1,21 +1,21 @@
package q5
import (
"fmt"
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
type Mysql struct {
host string
port int32
user string
passwd string
host string
port int32
user string
passwd string
database string
db *sql.DB
db *sql.DB
}
func (this* Mysql) init(host string, port int32, user string, passwd string, database string) {
func (this *Mysql) init(host string, port int32, user string, passwd string, database string) {
this.host = host
this.port = port
this.user = user
@ -23,7 +23,7 @@ func (this* Mysql) init(host string, port int32, user string, passwd string, dat
this.database = database
}
func (this* Mysql) Open() error {
func (this *Mysql) Open() error {
connStr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8",
this.user,
this.passwd,
@ -35,26 +35,26 @@ func (this* Mysql) Open() error {
return err
}
func (this* Mysql) Close() {
func (this *Mysql) Close() {
if this.db != nil {
this.db.Close()
}
}
func (this* Mysql) Ping() error {
func (this *Mysql) Ping() error {
return this.db.Ping()
}
func (this* Mysql) Query(query string, args ...interface{}) (*sql.Rows, error) {
func (this *Mysql) Query(query string, args ...interface{}) (*sql.Rows, error) {
rows, err := this.db.Query(query, args...)
return rows, err
}
func (this* Mysql) QueryRow(query string, args ...interface{}) *sql.Row {
func (this *Mysql) QueryRow(query string, args ...interface{}) *sql.Row {
return this.db.QueryRow(query, args...)
}
func (this* Mysql) Exec(query string, args ...interface{}) (sql.Result, error) {
func (this *Mysql) Exec(query string, args ...interface{}) (sql.Result, error) {
result, err := this.db.Exec(query, args...)
return result, err
}

View File

@ -6,7 +6,7 @@ import (
type Queue struct {
msgMutex sync.Mutex
msgList ListHead
msgList ListHead
WorkList ListHead
}

View File

@ -5,20 +5,20 @@ import (
)
type Redis struct {
host string
port int32
host string
port int32
passwd string
conn *redis.Conn
conn *redis.Conn
}
func (this* Redis) Init(host string, port int32, passwd string) {
func (this *Redis) Init(host string, port int32, passwd string) {
this.host = host
this.port = port
this.passwd = passwd
}
func (this* Redis) Open() {
func (this *Redis) Open() {
}
func (this* Redis) Close() {
func (this *Redis) Close() {
}

View File

@ -1,18 +1,18 @@
package q5
import (
"io"
"strings"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"encoding/json"
"encoding/base64"
"hash/crc32"
"io"
"strings"
)
const (
JSON_NONE = 0
JSON_ARRAY = iota
JSON_NONE = 0
JSON_ARRAY = iota
JSON_OBJECT = iota
)
@ -82,16 +82,16 @@ func ConvertUpperCamelCase(name string) string {
preIs_ := false
for i := 0; i < len(name); i++ {
if i == 0 {
newName += strings.ToUpper(name[i:i +1])
newName += strings.ToUpper(name[i : i+1])
preIs_ = name[i] == '_'
} else {
if preIs_ {
if name[i] != '_' {
newName += strings.ToUpper(name[i:i +1])
newName += strings.ToUpper(name[i : i+1])
}
} else {
if name[i] != '_' {
newName += name[i:i +1]
newName += name[i : i+1]
}
}
preIs_ = name[i] == '_'

View File

@ -1,6 +1,6 @@
package q5
type TimerCb func (int32, *Args)
type TimerCb func(int32, *Args)
type Args []interface{}
type Module interface {

View File

@ -5,7 +5,7 @@ import (
"time"
)
const Q5_EPOCH = 1419120000000;
const Q5_EPOCH = 1419120000000
const MACHINE_ID_BIT_NUM = 12
const SEQUNCE_ID_BIT_NUM = 10
@ -13,8 +13,8 @@ const MAX_MACHINE_ID = (1 << MACHINE_ID_BIT_NUM) - 1
const MAX_SEQUNCE_ID = (1 << SEQUNCE_ID_BIT_NUM) - 1
type Uuid struct {
machineId int32
sequenceId int32
machineId int32
sequenceId int32
lastGenerateTick int64
}