refactor, sketch SSE implementation

This commit is contained in:
Carl Pearson
2024-10-19 06:02:54 -06:00
parent 459e899efe
commit 22a82d0e4c
11 changed files with 266 additions and 124 deletions

26
handlers/session.go Normal file
View File

@@ -0,0 +1,26 @@
package handlers
import (
"fmt"
"github.com/labstack/echo/v4"
)
type User struct {
Id uint
}
func GetUser(c echo.Context) (User, error) {
session, err := store.Get(c.Request(), "session")
if err == nil {
val, ok := session.Values["user_id"]
if ok {
return User{Id: val.(uint)}, nil
} else {
return User{}, fmt.Errorf("user_id not in session")
}
} else {
return User{}, fmt.Errorf("couldn't retureve session from store")
}
}