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

View File

@ -1,10 +1,10 @@
package q5
import (
"errors"
"io/ioutil"
"net/http"
net_url "net/url"
"io/ioutil"
"errors"
//"strings"
)
@ -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,8 +1,8 @@
package q5
import (
"fmt"
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
@ -15,7 +15,7 @@ type Mysql struct {
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

@ -11,14 +11,14 @@ type Redis struct {
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,13 +1,13 @@
package q5
import (
"io"
"strings"
"crypto/md5"
"encoding/base64"
"encoding/hex"
"encoding/json"
"encoding/base64"
"hash/crc32"
"io"
"strings"
)
const (
@ -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