Optimisation

This commit is contained in:
Alexei Anoshenko 2026-07-22 18:47:24 +03:00
parent a8679fbd26
commit e9b128bc35
2 changed files with 10 additions and 0 deletions

View File

@ -155,6 +155,15 @@ func setSessionIDCookie(w http.ResponseWriter, sessionID int) {
http.SetCookie(w, &cookie) http.SetCookie(w, &cookie)
} }
func getSessionIDCookie(req *http.Request) (int, error) {
cookie, err := req.Cookie("session")
if err != nil {
return 0, err
}
return strconv.Atoi(cookie.Value)
}
func (app *application) postHandler(w http.ResponseWriter, req *http.Request) { func (app *application) postHandler(w http.ResponseWriter, req *http.Request) {
if reqBody, err := io.ReadAll(req.Body); err == nil { if reqBody, err := io.ReadAll(req.Body); err == nil {

View File

@ -44,6 +44,7 @@ func (session *sessionData) ClientStorage() ClientStorage {
if session.clientStorage == nil { if session.clientStorage == nil {
storage := new(clientStorageData) storage := new(clientStorageData)
storage.bridge = session.bridge storage.bridge = session.bridge
storage.getResult = map[int]func(string, string){}
session.clientStorage = storage session.clientStorage = storage
} }
return session.clientStorage return session.clientStorage