mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
ghttp.Session updates
This commit is contained in:
@ -87,7 +87,7 @@ func (s *Session) BatchSet(m map[string]interface{}) {
|
||||
|
||||
// 判断键名是否存在
|
||||
func (s *Session) Contains (key string) bool {
|
||||
if len(s.id) > 0 || s.request.Cookie.GetSessionId() != "" {
|
||||
if len(s.id) > 0 || s.request.Cookie.Contains(s.server.GetSessionIdName()) {
|
||||
s.init()
|
||||
return s.data.Contains(key)
|
||||
}
|
||||
@ -96,7 +96,7 @@ func (s *Session) Contains (key string) bool {
|
||||
|
||||
// 获取SESSION
|
||||
func (s *Session) Get (key string) interface{} {
|
||||
if len(s.id) > 0 || s.request.Cookie.GetSessionId() != "" {
|
||||
if len(s.id) > 0 || s.request.Cookie.Contains(s.server.GetSessionIdName()) {
|
||||
s.init()
|
||||
return s.data.Get(key)
|
||||
}
|
||||
@ -108,43 +108,9 @@ func (s *Session) GetVar(key string) gvar.VarRead {
|
||||
return gvar.NewRead(s.Get(key), true)
|
||||
}
|
||||
|
||||
|
||||
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) 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) 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) 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) 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) 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)) }
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
// (已废弃, 请使用GetVar) 将变量转换为对象,注意 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(key string) {
|
||||
if len(s.id) > 0 || s.request.Cookie.GetSessionId() != "" {
|
||||
if len(s.id) > 0 || s.request.Cookie.Contains(s.server.GetSessionIdName()) {
|
||||
s.init()
|
||||
s.data.Remove(key)
|
||||
}
|
||||
@ -152,7 +118,7 @@ func (s *Session) Remove(key string) {
|
||||
|
||||
// 清空session
|
||||
func (s *Session) Clear() {
|
||||
if len(s.id) > 0 || s.request.Cookie.GetSessionId() != "" {
|
||||
if len(s.id) > 0 || s.request.Cookie.Contains(s.server.GetSessionIdName()) {
|
||||
s.init()
|
||||
s.data.Clear()
|
||||
}
|
||||
@ -163,4 +129,116 @@ func (s *Session) UpdateExpire() {
|
||||
if len(s.id) > 0 {
|
||||
s.server.sessions.Set(s.id, s.data, s.server.GetSessionMaxAge()*1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetString(key string) string {
|
||||
return gconv.String(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetBool(key string) bool {
|
||||
return gconv.Bool(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInt(key string) int {
|
||||
return gconv.Int(s.Get(key)) }
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInt8(key string) int8 {
|
||||
return gconv.Int8(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInt16(key string) int16 {
|
||||
return gconv.Int16(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInt32(key string) int32 {
|
||||
return gconv.Int32(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInt64(key string) int64 {
|
||||
return gconv.Int64(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetUint(key string) uint {
|
||||
return gconv.Uint(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetUint8(key string) uint8 {
|
||||
return gconv.Uint8(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetUint16(key string) uint16 {
|
||||
return gconv.Uint16(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetUint32(key string) uint32 {
|
||||
return gconv.Uint32(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetUint64(key string) uint64 {
|
||||
return gconv.Uint64(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetFloat32(key string) float32 {
|
||||
return gconv.Float32(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetFloat64(key string) float64 {
|
||||
return gconv.Float64(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetBytes(key string) []byte {
|
||||
return gconv.Bytes(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInts(key string) []int {
|
||||
return gconv.Ints(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetFloats(key string) []float64 {
|
||||
return gconv.Floats(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetStrings(key string) []string {
|
||||
return gconv.Strings(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetInterfaces(key string) []interface{} {
|
||||
return gconv.Interfaces(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetTime(key string, format...string) time.Time {
|
||||
return gconv.Time(s.Get(key), format...)
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
func (s *Session) GetTimeDuration(key string) time.Duration {
|
||||
return gconv.TimeDuration(s.Get(key))
|
||||
}
|
||||
|
||||
// Deprecated, use GetVar instead.
|
||||
// (已废弃, 请使用GetVar) 将变量转换为对象,注意 objPointer 参数必须为struct指针
|
||||
func (s *Session) GetStruct(key string, objPointer interface{}, attrMapping...map[string]string) error {
|
||||
return gconv.Struct(s.Get(key), objPointer, attrMapping...)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user