This commit is contained in:
WA 2025-06-13 17:51:15 +02:00
parent a653d73f50
commit ce5aca3908

View file

@ -3,6 +3,7 @@ package files
import (
"fmt"
"os"
"sync"
)
@ -21,10 +22,12 @@ type ProviderFiles struct {
lock sync.Mutex
}
func (pder *ProviderFiles) ckdir() string {
return pder.sessPath + sessDir
func (pder *ProviderFiles) ckdirpath(sid string) string {
return fmt.Sprintf("%s/%s/%s.%s", pder.sessPath, sessDir, sid, sessExt)
}
func (pder *ProviderFiles) updateAtime(sid string) {}
// SetParams for files session provider set base path in filesystem for save sessions
func (pder *ProviderFiles) SetParams(p any) (err error) {
if p != nil {
@ -32,13 +35,19 @@ func (pder *ProviderFiles) SetParams(p any) (err error) {
pder.sessPath = s
return
}
return fmt.Errorf("Parameter for files session provider is not string")
return fmt.Errorf("parameter for files session provider is not string")
}
return fmt.Errorf("Parameter for files session provider must not be nil")
return fmt.Errorf("parameter for files session provider must not be nil")
}
// Init create session file if not exists and retturn *Session
func (pder *ProviderFiles) Init(sid string) (err error) {
//sessdir := sid + sessExt
return
pder.lock.Lock()
defer pder.lock.Unlock()
var fd *os.File
ckf := pder.ckdirpath(sid)
if fd, err = os.Create(ckf); err != nil {
return fmt.Errorf("create session file: %s failed with err: %w", ckf, err)
}
return fd.Close()
}