31 lines
530 B
Go
31 lines
530 B
Go
package rest
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"goAuth/internal/auth"
|
||
|
|
"goAuth/internal/user"
|
||
|
|
)
|
||
|
|
|
||
|
|
func userFromRequest(r *http.Request) *user.User {
|
||
|
|
value := r.Context().Value(auth.UserKey)
|
||
|
|
if value == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
u, _ := value.(*user.User)
|
||
|
|
return u
|
||
|
|
}
|
||
|
|
|
||
|
|
func sessionFromRequest(r *http.Request) *auth.Session {
|
||
|
|
value := r.Context().Value(auth.SessionKey)
|
||
|
|
if value == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
session, _ := value.(*auth.Session)
|
||
|
|
return session
|
||
|
|
}
|
||
|
|
|
||
|
|
func formatUserId(id int64) string {
|
||
|
|
return fmt.Sprintf("user-%d", id)
|
||
|
|
}
|