1
This commit is contained in:
parent
03ffea28fe
commit
bc3b2825a6
10
httpcli.go
10
httpcli.go
@ -67,15 +67,17 @@ func HttpGetAsJson(url string, params *XObject) (*XObject, string, error) {
|
|||||||
return respObj, respStr, err
|
return respObj, respStr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpPostContent(url string, contentType string, body string) (string, error) {
|
func HttpPostContent(url string, contentType string, body string, response *string) (error) {
|
||||||
|
*response = ""
|
||||||
resp, err := http.Post(url, contentType, strings.NewReader(body))
|
resp, err := http.Post(url, contentType, strings.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
if bytes, err := ioutil.ReadAll(resp.Body); err == nil {
|
||||||
return string(bytes), nil
|
*response = string(bytes)
|
||||||
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
47
listhead.go
47
listhead.go
@ -1,5 +1,7 @@
|
|||||||
package q5
|
package q5
|
||||||
|
|
||||||
|
type ListHead_Foreach_Func func(interface{}) bool
|
||||||
|
|
||||||
type ListHead struct {
|
type ListHead struct {
|
||||||
next *ListHead
|
next *ListHead
|
||||||
prev *ListHead
|
prev *ListHead
|
||||||
@ -27,6 +29,16 @@ func (this *ListHead) AddTail(pnew *ListHead) {
|
|||||||
prev.next = pnew
|
prev.next = pnew
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ListHead) AddHead(pnew *ListHead) {
|
||||||
|
prev := this
|
||||||
|
next := this.prev
|
||||||
|
|
||||||
|
next.prev = pnew
|
||||||
|
pnew.next = next
|
||||||
|
pnew.prev = prev
|
||||||
|
prev.next = pnew
|
||||||
|
}
|
||||||
|
|
||||||
func (this *ListHead) FirstEntry() interface{} {
|
func (this *ListHead) FirstEntry() interface{} {
|
||||||
return this.next.data
|
return this.next.data
|
||||||
}
|
}
|
||||||
@ -53,3 +65,38 @@ func (this *ListHead) DelInit() {
|
|||||||
this.next = this
|
this.next = this
|
||||||
this.prev = this
|
this.prev = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *ListHead) Next() *ListHead {
|
||||||
|
return this.next
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListHead) ForEachFrom(from *ListHead,
|
||||||
|
cb ListHead_Foreach_Func) {
|
||||||
|
for pos := from; pos != this; pos = pos.next {
|
||||||
|
if !cb(pos.data) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListHead) ForEach(cb ListHead_Foreach_Func) {
|
||||||
|
for pos := this.next; pos != this; pos = pos.next {
|
||||||
|
if !cb(pos.data) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ListHead) ForEach_r(cb ListHead_Foreach_Func) {
|
||||||
|
for pos := this.prev; pos != this; pos = pos.prev {
|
||||||
|
if !cb(pos.data) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeListHead () *ListHead{
|
||||||
|
l := new(ListHead)
|
||||||
|
l.Init(nil)
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
15
mysql.go
15
mysql.go
@ -1,6 +1,7 @@
|
|||||||
package q5
|
package q5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
@ -23,7 +24,13 @@ func (this* Mysql) init(host string, port int32, user string, passwd string, dat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this* Mysql) Open() error {
|
func (this* Mysql) Open() error {
|
||||||
db, err := sql.Open("mysql", "")
|
connStr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8",
|
||||||
|
this.user,
|
||||||
|
this.passwd,
|
||||||
|
this.host,
|
||||||
|
this.port,
|
||||||
|
this.database)
|
||||||
|
db, err := sql.Open("mysql", connStr)
|
||||||
this.db = db
|
this.db = db
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -39,16 +46,16 @@ func (this* Mysql) Ping() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
rows, err := this.db.Query(query, args...)
|
||||||
return rows, err
|
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)
|
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)
|
result, err := this.db.Exec(query, args...)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
strutils.go
12
strutils.go
@ -6,6 +6,7 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/base64"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,6 +22,17 @@ func Md5Str(data string) string {
|
|||||||
return hex.EncodeToString(h.Sum(nil))
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Base64Encode(data string) string {
|
||||||
|
strbytes := []byte(data)
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(strbytes)
|
||||||
|
return encoded
|
||||||
|
}
|
||||||
|
|
||||||
|
func Base64Decode(data string) (string, error) {
|
||||||
|
decoded, err := base64.StdEncoding.DecodeString(data)
|
||||||
|
return string(decoded), err
|
||||||
|
}
|
||||||
|
|
||||||
func Crc32(data string) uint32 {
|
func Crc32(data string) uint32 {
|
||||||
ieee := crc32.NewIEEE()
|
ieee := crc32.NewIEEE()
|
||||||
io.WriteString(ieee, data)
|
io.WriteString(ieee, data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user