1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-04 18:57:03 +00:00

update dependencies

This commit is contained in:
Gerasimos (Makis) Maropoulos
2025-08-15 23:29:20 +03:00
parent de4f462198
commit a8a3afea22
186 changed files with 694 additions and 689 deletions

View File

@@ -42,13 +42,13 @@ type Database interface {
OnUpdateExpiration(sid string, newExpires time.Duration) error
// Set sets a key value of a specific session.
// The "immutable" input argument depends on the store, it may not implement it at all.
Set(sid string, key string, value interface{}, ttl time.Duration, immutable bool) error
Set(sid string, key string, value any, ttl time.Duration, immutable bool) error
// Get retrieves a session value based on the key.
Get(sid string, key string) interface{}
Get(sid string, key string) any
// Decode binds the "outPtr" to the value associated to the provided "key".
Decode(sid, key string, outPtr interface{}) error
Decode(sid, key string, outPtr any) error
// Visit loops through all session keys and values.
Visit(sid string, cb func(key string, value interface{})) error
Visit(sid string, cb func(key string, value any)) error
// Len returns the length of the session's entries (keys).
Len(sid string) int
// Delete removes a session key value based on its key.
@@ -92,7 +92,7 @@ func (s *mem) Acquire(sid string, expires time.Duration) memstore.LifeTime {
func (s *mem) OnUpdateExpiration(string, time.Duration) error { return nil }
// immutable depends on the store, it may not implement it at all.
func (s *mem) Set(sid string, key string, value interface{}, _ time.Duration, immutable bool) error {
func (s *mem) Set(sid string, key string, value any, _ time.Duration, immutable bool) error {
s.mu.RLock()
store, ok := s.values[sid]
s.mu.RUnlock()
@@ -103,7 +103,7 @@ func (s *mem) Set(sid string, key string, value interface{}, _ time.Duration, im
return nil
}
func (s *mem) Get(sid string, key string) interface{} {
func (s *mem) Get(sid string, key string) any {
s.mu.RLock()
store, ok := s.values[sid]
s.mu.RUnlock()
@@ -114,7 +114,7 @@ func (s *mem) Get(sid string, key string) interface{} {
return nil
}
func (s *mem) Decode(sid string, key string, outPtr interface{}) error {
func (s *mem) Decode(sid string, key string, outPtr any) error {
v := s.Get(sid, key)
if v != nil {
reflect.ValueOf(outPtr).Set(reflect.ValueOf(v))
@@ -122,7 +122,7 @@ func (s *mem) Decode(sid string, key string, outPtr interface{}) error {
return nil
}
func (s *mem) Visit(sid string, cb func(key string, value interface{})) error {
func (s *mem) Visit(sid string, cb func(key string, value any)) error {
s.mu.RLock()
store, ok := s.values[sid]
s.mu.RUnlock()

View File

@@ -31,7 +31,7 @@ type (
flashMessage struct {
// if true then this flash message is removed on the flash gc
shouldRemove bool
value interface{}
value any
}
)
@@ -59,12 +59,12 @@ func (s *Session) IsNew() bool {
}
// Get returns a value based on its "key".
func (s *Session) Get(key string) interface{} {
func (s *Session) Get(key string) any {
return s.provider.db.Get(s.sid, key)
}
// Decode binds the given "outPtr" to the value associated to the provided "key".
func (s *Session) Decode(key string, outPtr interface{}) error {
func (s *Session) Decode(key string, outPtr any) error {
return s.provider.db.Decode(s.sid, key, outPtr)
}
@@ -97,7 +97,7 @@ func (s *Session) HasFlash() bool {
//
// Fetching a message deletes it from the session.
// This means that a message is meant to be displayed only on the first page served to the user.
func (s *Session) GetFlash(key string) interface{} {
func (s *Session) GetFlash(key string) any {
fv, ok := s.peekFlashMessage(key)
if !ok {
return nil
@@ -109,7 +109,7 @@ func (s *Session) GetFlash(key string) interface{} {
// PeekFlash returns a stored flash message based on its "key".
// Unlike GetFlash, this will keep the message valid for the next requests,
// until GetFlashes or GetFlash("key").
func (s *Session) PeekFlash(key string) interface{} {
func (s *Session) PeekFlash(key string) any {
fv, ok := s.peekFlashMessage(key)
if !ok {
return nil
@@ -181,7 +181,7 @@ func (s *Session) GetFlashStringDefault(key string, defaultValue string) string
// the value (if found) matched to the requested key-value pair of the session's memory storage.
type ErrEntryNotFound struct {
Err *memstore.ErrEntryNotFound
Value interface{}
Value any
}
func (e *ErrEntryNotFound) Error() string {
@@ -195,7 +195,7 @@ func (e *ErrEntryNotFound) Unwrap() error {
// As method implements the dynamic As interface of the std errors package.
// As should be NOT used directly, use `errors.As` instead.
func (e *ErrEntryNotFound) As(target interface{}) bool {
func (e *ErrEntryNotFound) As(target any) bool {
if v, ok := target.(*memstore.ErrEntryNotFound); ok && e.Err != nil {
return e.Err.As(v)
}
@@ -222,7 +222,7 @@ func (e *ErrEntryNotFound) As(target interface{}) bool {
return true
}
func newErrEntryNotFound(key string, kind reflect.Kind, value interface{}) *ErrEntryNotFound {
func newErrEntryNotFound(key string, kind reflect.Kind, value any) *ErrEntryNotFound {
return &ErrEntryNotFound{Err: &memstore.ErrEntryNotFound{Key: key, Kind: kind}, Value: value}
}
@@ -485,20 +485,20 @@ func (s *Session) GetBooleanDefault(key string, defaultValue bool) bool {
}
// GetAll returns a copy of all session's values.
func (s *Session) GetAll() map[string]interface{} {
items := make(map[string]interface{}, s.provider.db.Len(s.sid))
func (s *Session) GetAll() map[string]any {
items := make(map[string]any, s.provider.db.Len(s.sid))
s.mu.RLock()
s.provider.db.Visit(s.sid, func(key string, value interface{}) {
s.provider.db.Visit(s.sid, func(key string, value any) {
items[key] = value
})
s.mu.RUnlock()
return items
}
// GetFlashes returns all flash messages as map[string](key) and interface{} value
// GetFlashes returns all flash messages as map[string](key) and any value
// NOTE: this will cause at remove all current flash messages on the next request of the same user.
func (s *Session) GetFlashes() map[string]interface{} {
flashes := make(map[string]interface{}, len(s.flashes))
func (s *Session) GetFlashes() map[string]any {
flashes := make(map[string]any, len(s.flashes))
s.mu.Lock()
for key, v := range s.flashes {
flashes[key] = v.value
@@ -509,7 +509,7 @@ func (s *Session) GetFlashes() map[string]interface{} {
}
// Visit loops each of the entries and calls the callback function func(key, value).
func (s *Session) Visit(cb func(k string, v interface{})) {
func (s *Session) Visit(cb func(k string, v any)) {
s.provider.db.Visit(s.sid, cb)
}
@@ -518,12 +518,12 @@ func (s *Session) Len() int {
return s.provider.db.Len(s.sid)
}
func (s *Session) set(key string, value interface{}, immutable bool) {
func (s *Session) set(key string, value any, immutable bool) {
s.provider.db.Set(s.sid, key, value, s.Lifetime.DurationUntilExpiration(), immutable)
}
// Set fills the session with an entry "value", based on its "key".
func (s *Session) Set(key string, value interface{}) {
func (s *Session) Set(key string, value any) {
s.set(key, value, false)
}
@@ -533,7 +533,7 @@ func (s *Session) Set(key string, value interface{}) {
// if the entry was immutable, for your own safety.
// Use it consistently, it's far slower than `Set`.
// Read more about muttable and immutable go types: https://stackoverflow.com/a/8021081
func (s *Session) SetImmutable(key string, value interface{}) {
func (s *Session) SetImmutable(key string, value any) {
s.set(key, value, true)
}
@@ -557,7 +557,7 @@ func (s *Session) SetImmutable(key string, value interface{}) {
//
// In this example we used the key 'success'.
// If you want to define more than one flash messages, you will have to use different keys.
func (s *Session) SetFlash(key string, value interface{}) {
func (s *Session) SetFlash(key string, value any) {
s.mu.Lock()
if s.flashes == nil {
s.flashes = make(map[string]*flashMessage)

View File

@@ -127,7 +127,7 @@ func makeKey(sid, key string) []byte {
// Set sets a key value of a specific session.
// Ignore the "immutable".
func (db *Database) Set(sid string, key string, value interface{}, ttl time.Duration, immutable bool) error {
func (db *Database) Set(sid string, key string, value any, ttl time.Duration, immutable bool) error {
valueBytes, err := sessions.DefaultTranscoder.Marshal(value)
if err != nil {
db.logger.Error(err)
@@ -146,7 +146,7 @@ func (db *Database) Set(sid string, key string, value interface{}, ttl time.Dura
}
// Get retrieves a session value based on the key.
func (db *Database) Get(sid string, key string) (value interface{}) {
func (db *Database) Get(sid string, key string) (value any) {
if err := db.Decode(sid, key, &value); err == nil {
return value
}
@@ -155,7 +155,7 @@ func (db *Database) Get(sid string, key string) (value interface{}) {
}
// Decode binds the "outPtr" to the value associated to the provided "key".
func (db *Database) Decode(sid, key string, outPtr interface{}) error {
func (db *Database) Decode(sid, key string, outPtr any) error {
err := db.Service.View(func(txn *badger.Txn) error {
item, err := txn.Get(makeKey(sid, key))
if err != nil {
@@ -181,7 +181,7 @@ func validSessionItem(key, prefix []byte) bool {
}
// Visit loops through all session keys and values.
func (db *Database) Visit(sid string, cb func(key string, value interface{})) error {
func (db *Database) Visit(sid string, cb func(key string, value any)) error {
prefix := makePrefix(sid)
txn := db.Service.NewTransaction(false)
@@ -201,7 +201,7 @@ func (db *Database) Visit(sid string, cb func(key string, value interface{})) er
continue
}
var value interface{}
var value any
err := item.Value(func(valueBytes []byte) error {
return sessions.DefaultTranscoder.Unmarshal(valueBytes, &value)

View File

@@ -254,7 +254,7 @@ func makeKey(key string) []byte {
// Set sets a key value of a specific session.
// Ignore the "immutable".
func (db *Database) Set(sid string, key string, value interface{}, ttl time.Duration, immutable bool) error {
func (db *Database) Set(sid string, key string, value any, ttl time.Duration, immutable bool) error {
valueBytes, err := sessions.DefaultTranscoder.Marshal(value)
if err != nil {
db.logger.Debug(err)
@@ -282,7 +282,7 @@ func (db *Database) Set(sid string, key string, value interface{}, ttl time.Dura
}
// Get retrieves a session value based on the key.
func (db *Database) Get(sid string, key string) (value interface{}) {
func (db *Database) Get(sid string, key string) (value any) {
if err := db.Decode(sid, key, &value); err == nil {
return value
}
@@ -291,7 +291,7 @@ func (db *Database) Get(sid string, key string) (value interface{}) {
}
// Decode binds the "outPtr" to the value associated to the provided "key".
func (db *Database) Decode(sid, key string, outPtr interface{}) error {
func (db *Database) Decode(sid, key string, outPtr any) error {
err := db.Service.View(func(tx *bolt.Tx) error {
b := db.getBucketForSession(tx, sid)
if b == nil {
@@ -313,7 +313,7 @@ func (db *Database) Decode(sid, key string, outPtr interface{}) error {
}
// Visit loops through all session keys and values.
func (db *Database) Visit(sid string, cb func(key string, value interface{})) error {
func (db *Database) Visit(sid string, cb func(key string, value any)) error {
err := db.Service.View(func(tx *bolt.Tx) error {
b := db.getBucketForSession(tx, sid)
if b == nil {
@@ -321,7 +321,7 @@ func (db *Database) Visit(sid string, cb func(key string, value interface{})) er
}
return b.ForEach(func(k []byte, v []byte) error {
var value interface{}
var value any
if err := sessions.DefaultTranscoder.Unmarshal(v, &value); err != nil {
db.logger.Debugf("unable to retrieve value of key '%s' of '%s': %v", k, sid, err)
return err

View File

@@ -165,7 +165,7 @@ func (db *Database) OnUpdateExpiration(sid string, newExpires time.Duration) err
// Set sets a key value of a specific session.
// Ignore the "immutable".
func (db *Database) Set(sid string, key string, value interface{}, _ time.Duration, _ bool) error {
func (db *Database) Set(sid string, key string, value any, _ time.Duration, _ bool) error {
valueBytes, err := sessions.DefaultTranscoder.Marshal(value)
if err != nil {
db.logger.Error(err)
@@ -181,7 +181,7 @@ func (db *Database) Set(sid string, key string, value interface{}, _ time.Durati
}
// Get retrieves a session value based on the key.
func (db *Database) Get(sid string, key string) (value interface{}) {
func (db *Database) Get(sid string, key string) (value any) {
if err := db.Decode(sid, key, &value); err == nil {
return value
}
@@ -190,7 +190,7 @@ func (db *Database) Get(sid string, key string) (value interface{}) {
}
// Decode binds the "outPtr" to the value associated to the provided "key".
func (db *Database) Decode(sid, key string, outPtr interface{}) error {
func (db *Database) Decode(sid, key string, outPtr any) error {
sidKey := db.makeSID(sid)
data, err := db.c.Driver.Get(sidKey, key)
if err != nil {
@@ -206,7 +206,7 @@ func (db *Database) Decode(sid, key string, outPtr interface{}) error {
return nil
}
func (db *Database) decodeValue(val interface{}, outPtr interface{}) error {
func (db *Database) decodeValue(val any, outPtr any) error {
if val == nil {
return nil
}
@@ -234,14 +234,14 @@ func (db *Database) keys(fullSID string) []string {
}
// Visit loops through all session keys and values.
func (db *Database) Visit(sid string, cb func(key string, value interface{})) error {
func (db *Database) Visit(sid string, cb func(key string, value any)) error {
kv, err := db.c.Driver.GetAll(db.makeSID(sid))
if err != nil {
return err
}
for k, v := range kv {
var value interface{} // new value each time, we don't know what user will do in "cb".
var value any // new value each time, we don't know what user will do in "cb".
if err = db.decodeValue(v, &value); err != nil {
db.logger.Debugf("unable to decode %s:%s: %v", sid, k, err)
return err

View File

@@ -8,8 +8,8 @@ type Driver interface {
Connect(c Config) error
PingPong() (bool, error)
CloseConnection() error
Set(sid, key string, value interface{}) error
Get(sid, key string) (interface{}, error)
Set(sid, key string, value any) error
Get(sid, key string) (any, error)
Exists(sid string) bool
TTL(sid string) time.Duration
UpdateTTL(sid string, newLifetime time.Duration) error

View File

@@ -150,12 +150,12 @@ func (r *GoRedisDriver) CloseConnection() error {
// Set stores a "value" based on the session's "key".
// The value should be type of []byte, so unmarshal can happen.
func (r *GoRedisDriver) Set(sid, key string, value interface{}) error {
func (r *GoRedisDriver) Set(sid, key string, value any) error {
return r.Client.HSet(defaultContext, sid, key, value).Err()
}
// Get returns the associated value of the session's given "key".
func (r *GoRedisDriver) Get(sid, key string) (interface{}, error) {
func (r *GoRedisDriver) Get(sid, key string) (any, error) {
return r.Client.HGet(defaultContext, sid, key).Bytes()
}

View File

@@ -165,7 +165,7 @@ func (s *Sessions) Start(ctx *context.Context, cookieOptions ...context.CookieOp
// n := s.provider.db.Len(sid)
// fmt.Printf("db.Len(%s) = %d\n", sid, n)
// if n > 0 {
// s.provider.db.Visit(sid, func(key string, value interface{}) {
// s.provider.db.Visit(sid, func(key string, value any) {
// fmt.Printf("%s=%s\n", key, value)
// })
// }

View File

@@ -25,7 +25,7 @@ const (
)
func testSessions(t *testing.T, app *iris.Application) {
values := map[string]interface{}{
values := map[string]any{
"Name": "iris",
"Months": "4",
"Secret": "dsads£2132215£%%Ssdsa",
@@ -47,7 +47,7 @@ func testSessions(t *testing.T, app *iris.Application) {
app.Post("/set", func(ctx *context.Context) {
s := sessions.Get(ctx)
vals := make(map[string]interface{})
vals := make(map[string]any)
if err := ctx.ReadJSON(&vals); err != nil {
t.Fatalf("Cannot read JSON. Trace %s", err.Error())
}
@@ -134,18 +134,18 @@ func TestFlashMessages(t *testing.T) {
valueSingleKey := "Name"
valueSingleValue := "iris-sessions"
values := map[string]interface{}{
values := map[string]any{
valueSingleKey: valueSingleValue,
"Days": "1",
"Secret": "dsads£2132215£%%Ssdsa",
}
writeValues := func(ctx *context.Context, values map[string]interface{}) error {
writeValues := func(ctx *context.Context, values map[string]any) error {
return ctx.JSON(values)
}
app.Post("/set", func(ctx *context.Context) {
vals := make(map[string]interface{})
vals := make(map[string]any)
if err := ctx.ReadJSON(&vals); err != nil {
t.Fatalf("Cannot readjson. Trace %s", err.Error())
}

View File

@@ -15,11 +15,11 @@ func init() {
type (
// Marshaler is the common marshaler interface, used by transcoder.
Marshaler interface {
Marshal(interface{}) ([]byte, error)
Marshal(any) ([]byte, error)
}
// Unmarshaler is the common unmarshaler interface, used by transcoder.
Unmarshaler interface {
Unmarshal([]byte, interface{}) error
Unmarshal([]byte, any) error
}
// Transcoder is the interface that transcoders should implement, it includes just the `Marshaler` and the `Unmarshaler`.
Transcoder interface {
@@ -64,7 +64,7 @@ var (
DefaultTranscoder Transcoder = defaultTranscoder{}
)
func (defaultTranscoder) Marshal(value interface{}) ([]byte, error) {
func (defaultTranscoder) Marshal(value any) ([]byte, error) {
if tr, ok := value.(Marshaler); ok {
return tr.Marshal(value)
}
@@ -76,7 +76,7 @@ func (defaultTranscoder) Marshal(value interface{}) ([]byte, error) {
return json.Marshal(value)
}
func (defaultTranscoder) Unmarshal(b []byte, outPtr interface{}) error {
func (defaultTranscoder) Unmarshal(b []byte, outPtr any) error {
if tr, ok := outPtr.(Unmarshaler); ok {
return tr.Unmarshal(b, outPtr)
}
@@ -89,7 +89,7 @@ func (defaultTranscoder) Unmarshal(b []byte, outPtr interface{}) error {
}
// Marshal returns the gob encoding of "value".
func (GobTranscoder) Marshal(value interface{}) ([]byte, error) {
func (GobTranscoder) Marshal(value any) ([]byte, error) {
var (
w = new(bytes.Buffer)
enc = gob.NewEncoder(w)
@@ -111,7 +111,7 @@ func (GobTranscoder) Marshal(value interface{}) ([]byte, error) {
// Unmarshal parses the gob-encoded data "b" and stores the result
// in the value pointed to by "outPtr".
func (GobTranscoder) Unmarshal(b []byte, outPtr interface{}) error {
func (GobTranscoder) Unmarshal(b []byte, outPtr any) error {
dec := gob.NewDecoder(bytes.NewBuffer(b))
if v, ok := outPtr.(reflect.Value); ok {