21 lines
500 B
Go
21 lines
500 B
Go
package controller
|
|
|
|
import (
|
|
"electricity_bill_calc/exceptions"
|
|
"electricity_bill_calc/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func _retreiveSession(c *gin.Context) (*model.Session, error) {
|
|
session, exists := c.Get("session")
|
|
if !exists {
|
|
return nil, exceptions.NewUnauthorizedError("用户会话不存在")
|
|
}
|
|
userSession, ok := session.(*model.Session)
|
|
if !ok {
|
|
return nil, exceptions.NewUnauthorizedError("用户会话格式不正确,需要重新登录")
|
|
}
|
|
return userSession, nil
|
|
}
|