2021-12-08 18:43:14 +03:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2021-12-09 17:02:57 +03:00
|
|
|
type Response struct {
|
|
|
|
Succeed bool `json:"succeed"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
Data interface{} `json:"data"`
|
|
|
|
}
|
|
|
|
|
2021-12-10 08:41:17 +03:00
|
|
|
func GetUserIdInSession(r *http.Request) (string, error) {
|
|
|
|
session, _ := SessionStore.Get(r, "session")
|
2021-12-08 18:43:14 +03:00
|
|
|
|
2021-12-10 08:41:17 +03:00
|
|
|
userId, ok := session.Values["user_id"].(string)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return "", http.ErrNoCookie
|
2021-12-09 17:02:57 +03:00
|
|
|
}
|
|
|
|
|
2021-12-10 08:41:17 +03:00
|
|
|
return userId, nil
|
2021-12-08 18:43:14 +03:00
|
|
|
}
|