mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
框架部分模块优化
This commit is contained in:
3
TODO
3
TODO
@ -11,7 +11,7 @@ Cookie&Session数据池化处理;
|
||||
ghttp.Client增加proxy特性;
|
||||
gtime增加对时区转换的封装,并简化失去转换时对类似+80500时区的支持;
|
||||
改进gf-orm的where查询功能,参考thinkphp 里的where查询语法;
|
||||
改进ghttp.Server平滑重启机制,当新进程接管服务后,再使用进程间通信方式通知父进程销毁;
|
||||
|
||||
|
||||
|
||||
DONE:
|
||||
@ -40,6 +40,7 @@ DONE:
|
||||
23. 平滑重启机制改进,以便于开发阶段调试;
|
||||
24. 对grpool进行优化改进,包括属性原子操作封装采用gtype实现,修正设计BUG:https://github.com/johng-cn/gf/issues/6;
|
||||
25. gredis增加redis密码支持;
|
||||
26. 改进ghttp.Server平滑重启机制,当新进程接管服务后,再使用进程间通信方式通知父进程销毁;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,25 +6,24 @@
|
||||
|
||||
// go test *.go -bench=".*"
|
||||
|
||||
package gmap_test
|
||||
package gmap
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"gitee.com/johng/gf/g/container/gmap"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
||||
var ibm = gmap.NewIntBoolMap()
|
||||
var iim = gmap.NewIntIntMap()
|
||||
var iifm = gmap.NewIntInterfaceMap()
|
||||
var ism = gmap.NewIntStringMap()
|
||||
var ififm = gmap.NewInterfaceInterfaceMap()
|
||||
var sbm = gmap.NewStringBoolMap()
|
||||
var sim = gmap.NewStringIntMap()
|
||||
var sifm = gmap.NewStringInterfaceMap()
|
||||
var ssm = gmap.NewStringStringMap()
|
||||
var uifm = gmap.NewUintInterfaceMap()
|
||||
var ibm = NewIntBoolMap()
|
||||
var iim = NewIntIntMap()
|
||||
var iifm = NewIntInterfaceMap()
|
||||
var ism = NewIntStringMap()
|
||||
var ififm = NewInterfaceInterfaceMap()
|
||||
var sbm = NewStringBoolMap()
|
||||
var sim = NewStringIntMap()
|
||||
var sifm = NewStringInterfaceMap()
|
||||
var ssm = NewStringStringMap()
|
||||
var uifm = NewUintInterfaceMap()
|
||||
|
||||
func BenchmarkIntBoolMap_Set(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
@ -89,10 +89,42 @@ func (this *IntInterfaceMap) GetInt(key int) int {
|
||||
return gconv.Int(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetInt8(key int) int8 {
|
||||
return gconv.Int8(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetInt16(key int) int16 {
|
||||
return gconv.Int16(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetInt32(key int) int32 {
|
||||
return gconv.Int32(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetInt64(key int) int64 {
|
||||
return gconv.Int64(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetUint (key int) uint {
|
||||
return gconv.Uint(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetUint8 (key int) uint8 {
|
||||
return gconv.Uint8(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetUint16 (key int) uint16 {
|
||||
return gconv.Uint16(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetUint32 (key int) uint32 {
|
||||
return gconv.Uint32(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetUint64 (key int) uint64 {
|
||||
return gconv.Uint64(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetFloat32 (key int) float32 {
|
||||
return gconv.Float32(this.Get(key))
|
||||
}
|
||||
@ -105,6 +137,10 @@ func (this *IntInterfaceMap) GetString (key int) string {
|
||||
return gconv.String(this.Get(key))
|
||||
}
|
||||
|
||||
func (this *IntInterfaceMap) GetStrings (key int) []string {
|
||||
return gconv.Strings(this.Get(key))
|
||||
}
|
||||
|
||||
// 删除键值对
|
||||
func (this *IntInterfaceMap) Remove(key int) {
|
||||
this.mu.Lock()
|
||||
|
||||
@ -101,9 +101,13 @@ func Load (path string) (*Json, error) {
|
||||
}
|
||||
|
||||
// 支持的配置文件格式:xml, json, yaml/yml, toml
|
||||
func LoadContent (data []byte, t string) (*Json, error) {
|
||||
func LoadContent (data []byte, dataType...string) (*Json, error) {
|
||||
var err error
|
||||
var result interface{}
|
||||
t := "json"
|
||||
if len(dataType) > 0 {
|
||||
t = dataType[0]
|
||||
}
|
||||
switch t {
|
||||
case "xml": fallthrough
|
||||
case ".xml":
|
||||
|
||||
@ -32,9 +32,9 @@ func Load (path string) (*Parser, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// 支持的配置文件格式:xml, json, yaml/yml, toml
|
||||
func LoadContent (data []byte, fileType string) (*Parser, error) {
|
||||
if j, e := gjson.LoadContent(data, fileType); e == nil {
|
||||
// 支持的数据内容格式:json(默认), xml, yaml/yml, toml
|
||||
func LoadContent (data []byte, dataType...string) (*Parser, error) {
|
||||
if j, e := gjson.LoadContent(data, dataType...); e == nil {
|
||||
return &Parser{j}, nil
|
||||
} else {
|
||||
return nil, e
|
||||
|
||||
@ -12,7 +12,6 @@ package ghttp
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
"strings"
|
||||
"net/http"
|
||||
"gitee.com/johng/gf/g/os/gtime"
|
||||
)
|
||||
@ -43,7 +42,7 @@ func GetCookie(r *Request) *Cookie {
|
||||
}
|
||||
c := &Cookie {
|
||||
data : make(map[string]CookieItem),
|
||||
domain : strings.Split(r.Host, ":")[0],
|
||||
domain : r.GetHost(),
|
||||
server : r.Server,
|
||||
request : r,
|
||||
response : r.Response,
|
||||
@ -53,15 +52,13 @@ func GetCookie(r *Request) *Cookie {
|
||||
return c
|
||||
}
|
||||
|
||||
// 从请求流中初始化
|
||||
// 从请求流中初始化,无锁
|
||||
func (c *Cookie) init() {
|
||||
c.mu.Lock()
|
||||
for _, v := range c.request.Cookies() {
|
||||
c.data[v.Name] = CookieItem {
|
||||
v.Value, v.Domain, v.Path, v.Expires.Second(), v.HttpOnly,
|
||||
}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// 获取所有的Cookie并构造成map返回
|
||||
@ -137,6 +134,7 @@ func (c *Cookie) Close() {
|
||||
func (c *Cookie) Output() {
|
||||
c.mu.RLock()
|
||||
for k, v := range c.data {
|
||||
// 只有expire != 0的才是服务端在本地请求中设置的cookie
|
||||
if v.expire == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -86,6 +86,10 @@ func (s *Session) GetUint (k string) uint {
|
||||
return gconv.Uint(s.Get(k))
|
||||
}
|
||||
|
||||
func (s *Session) GetUint8 (k string) uint8 {
|
||||
return gconv.Uint8(s.Get(k))
|
||||
}
|
||||
|
||||
func (s *Session) GetFloat32 (k string) float32 {
|
||||
return gconv.Float32(s.Get(k))
|
||||
}
|
||||
|
||||
@ -92,6 +92,15 @@ func Format(format string, timestamps...int64) string {
|
||||
}
|
||||
|
||||
// 字符串转换为时间对象,需要给定字符串时间格式,format格式形如:2006-01-02 15:04:05
|
||||
// 不传递自定义格式下默认支持的标准时间格式:
|
||||
// "2017-12-14 04:51:34 +0805 LMT",
|
||||
// "2006-01-02T15:04:05Z07:00",
|
||||
// "2014-01-17T01:19:15+08:00",
|
||||
// "2018-02-09T20:46:17.897Z",
|
||||
// "2018-02-09 20:46:17.897",
|
||||
// "2018-02-09T20:46:17Z",
|
||||
// "2018-02-09 20:46:17",
|
||||
// "2018-02-09",
|
||||
func StrToTime(str string, format...string) (time.Time, error) {
|
||||
// 优先使用用户输入日期格式进行转换
|
||||
if len(format) > 0 {
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
// 将变量i转换为字符串指定的类型t
|
||||
func Convert(i interface{}, t string) interface{} {
|
||||
func Convert(i interface{}, t string, params...interface{}) interface{} {
|
||||
switch t {
|
||||
case "int": return Int(i)
|
||||
case "int8": return Int8(i)
|
||||
@ -35,7 +35,12 @@ func Convert(i interface{}, t string) interface{} {
|
||||
case "bool": return Bool(i)
|
||||
case "string": return String(i)
|
||||
case "[]byte": return Bytes(i)
|
||||
case "time.Time": return Time(i)
|
||||
case "time.Time":
|
||||
if len(params) > 0 {
|
||||
return Time(i, String(params[0]))
|
||||
}
|
||||
return Time(i)
|
||||
|
||||
case "time.Duration": return TimeDuration(i)
|
||||
default:
|
||||
return i
|
||||
|
||||
@ -2,10 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
"gitee.com/johng/gf/g/encoding/gjson"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(gconv.Float64(float32(19.66)))
|
||||
fmt.Println(float64(float32(19.66)))
|
||||
content := `[0.00000000059, 1.598877777409]`
|
||||
j, _ := gjson.LoadContent([]byte(content), "json")
|
||||
fmt.Println(j.GetString("0"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user