mirror of
https://gitee.com/johng/gf
synced 2026-06-26 09:27:31 +08:00
改进SESSION方法
This commit is contained in:
8
TODO
8
TODO
@ -19,7 +19,6 @@ gfile文件stat信息使用gfsnotify进行缓存更新改进;
|
||||
ghttp.Server增加proxy功能特性,本地proxy和远程proxy,本地即将路由规则映射;远程即反向代理;
|
||||
gjson对大json数据的解析效率问题;
|
||||
ghttp增加route name特性,并同时支持backend和template(提供内置函数)引用,可以通过RedirectRoute方法给定route name和路由参数跳转到指定的路由地址上;
|
||||
ghttp日志增加客户端IP信息;
|
||||
ghttp.Client自动Close机制;
|
||||
gvalid校验支持当第一个规则失败后便不再校验后续的规则,最好做成链式操作;
|
||||
检查ghttp.Server超时问题;
|
||||
@ -35,7 +34,8 @@ ghttp.Request增加对输入参数的自动HtmlEncode机制;
|
||||
glog分类&日志等级&链式操作、gdb debug自动输出调试信息、gmlock内存锁、
|
||||
服务注册域名增加对泛域名的支持;
|
||||
服务注册时判断方法定义满足规范时才执行绑定,否则提示WARN信息;
|
||||
glog增加对日志文件名称的生成规则设定,支持时间格式规则;
|
||||
Cookie设置中文失效问题;
|
||||
ghttp hook回调使用方式在注册路由比较多的时候,优先级可能使得开发者混乱,考虑方式便于管理;
|
||||
|
||||
DONE:
|
||||
1. gconv完善针对不同类型的判断,例如:尽量减少sprintf("%v", xxx)来执行string类型的转换;
|
||||
@ -78,4 +78,6 @@ DONE:
|
||||
38. gfsnotify增加对于目录的监控;
|
||||
39. 检查windows下的平滑重启失效问题;
|
||||
40. ghttp.Server的Cookie及Session锁机制优化(去掉map锁机制);
|
||||
41. 解决glog串日志情况;
|
||||
41. 解决glog串日志情况;
|
||||
42. glog增加对日志文件名称的生成规则设定,支持时间格式规则;
|
||||
43. ghttp日志增加客户端IP信息;
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"gitee.com/johng/gf/g/util/grand"
|
||||
"gitee.com/johng/gf/g/util/gconv"
|
||||
"gitee.com/johng/gf/g/container/gmap"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 单个session对象
|
||||
@ -57,8 +58,8 @@ func (s *Session) Data () map[string]interface{} {
|
||||
}
|
||||
|
||||
// 设置session
|
||||
func (s *Session) Set (k string, v interface{}) {
|
||||
s.data.Set(k, v)
|
||||
func (s *Session) Set (key string, value interface{}) {
|
||||
s.data.Set(key, value)
|
||||
}
|
||||
|
||||
// 批量设置(BatchSet别名)
|
||||
@ -72,46 +73,52 @@ func (s *Session) BatchSet (m map[string]interface{}) {
|
||||
}
|
||||
|
||||
// 判断键名是否存在
|
||||
func (s *Session) Contains (k string) bool {
|
||||
return s.data.Get(k) != nil
|
||||
func (s *Session) Contains (key string) bool {
|
||||
return s.data.Contains(key)
|
||||
}
|
||||
|
||||
// 获取session
|
||||
func (s *Session) Get (k string) interface{} {
|
||||
return s.data.Get(k)
|
||||
}
|
||||
func (s *Session) Get (key string) interface{} { return s.data.Get(key) }
|
||||
func (s *Session) GetString (key string) string { return gconv.String(s.Get(key)) }
|
||||
func (s *Session) GetBool(key string) bool { return gconv.Bool(s.Get(key)) }
|
||||
|
||||
func (s *Session) GetString (k string) string {
|
||||
return gconv.String(s.Get(k))
|
||||
}
|
||||
func (s *Session) GetInt(key string) int { return gconv.Int(s.Get(key)) }
|
||||
func (s *Session) GetInt8(key string) int8 { return gconv.Int8(s.Get(key)) }
|
||||
func (s *Session) GetInt16(key string) int16 { return gconv.Int16(s.Get(key)) }
|
||||
func (s *Session) GetInt32(key string) int32 { return gconv.Int32(s.Get(key)) }
|
||||
func (s *Session) GetInt64(key string) int64 { return gconv.Int64(s.Get(key)) }
|
||||
|
||||
func (s *Session) GetBool (k string) bool {
|
||||
return gconv.Bool(s.Get(k))
|
||||
}
|
||||
func (s *Session) GetUint(key string) uint { return gconv.Uint(s.Get(key)) }
|
||||
func (s *Session) GetUint8(key string) uint8 { return gconv.Uint8(s.Get(key)) }
|
||||
func (s *Session) GetUint16(key string) uint16 { return gconv.Uint16(s.Get(key)) }
|
||||
func (s *Session) GetUint32(key string) uint32 { return gconv.Uint32(s.Get(key)) }
|
||||
func (s *Session) GetUint64(key string) uint64 { return gconv.Uint64(s.Get(key)) }
|
||||
|
||||
func (s *Session) GetInt (k string) int {
|
||||
return gconv.Int(s.Get(k))
|
||||
}
|
||||
func (s *Session) GetFloat32 (key string) float32 { return gconv.Float32(s.Get(key)) }
|
||||
func (s *Session) GetFloat64 (key string) float64 { return gconv.Float64(s.Get(key)) }
|
||||
|
||||
func (s *Session) GetUint (k string) uint {
|
||||
return gconv.Uint(s.Get(k))
|
||||
}
|
||||
func (s *Session) GetBytes(key string) []byte { return gconv.Bytes(s.Get(key)) }
|
||||
func (s *Session) GetInts(key string) []int { return gconv.Ints(s.Get(key)) }
|
||||
func (s *Session) GetFloats(key string) []float64 { return gconv.Floats(s.Get(key)) }
|
||||
func (s *Session) GetStrings(key string) []string { return gconv.Strings(s.Get(key)) }
|
||||
func (s *Session) GetInterfaces(key string) []interface{} { return gconv.Interfaces(s.Get(key)) }
|
||||
|
||||
func (s *Session) GetUint8 (k string) uint8 {
|
||||
return gconv.Uint8(s.Get(k))
|
||||
}
|
||||
func (s *Session) GetTime(key string, format...string) time.Time { return gconv.Time(s.Get(key), format...) }
|
||||
func (s *Session) GetTimeDuration(key string) time.Duration { return gconv.TimeDuration(s.Get(key)) }
|
||||
|
||||
func (s *Session) GetFloat32 (k string) float32 {
|
||||
return gconv.Float32(s.Get(k))
|
||||
}
|
||||
|
||||
func (s *Session) GetFloat64 (k string) float64 {
|
||||
return gconv.Float64(s.Get(k))
|
||||
// 将变量转换为对象,注意 objPointer 参数必须为struct指针
|
||||
func (s *Session) GetStruct(key string, objPointer interface{}, attrMapping...map[string]string) error {
|
||||
return gconv.Struct(s.Get(key), objPointer, attrMapping...)
|
||||
}
|
||||
|
||||
// 删除session
|
||||
func (s *Session) Remove (k string) {
|
||||
s.data.Remove(k)
|
||||
func (s *Session) Remove (key string) {
|
||||
s.data.Remove(key)
|
||||
}
|
||||
|
||||
// 清空session
|
||||
func (s *Session) Clear () {
|
||||
s.data.Clear()
|
||||
}
|
||||
|
||||
// 更新过期时间(如果用在守护进程中长期使用,需要手动调用进行更新,防止超时被清除)
|
||||
|
||||
@ -3,13 +3,11 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/util/grand"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(uint(-1))
|
||||
os.Exit(0)
|
||||
for i := 0; i < 10; i++ {
|
||||
//fmt.Println(grand.RandStr(3))
|
||||
fmt.Println(grand.Rand(100, 200))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user