Initial
This commit is contained in:
commit
97dc0a3570
78 files changed
+7054
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"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 clientAddress(r *http.Request) string {
|
||||
host, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
func formatUserId(id int64) string {
|
||||
return fmt.Sprintf("user-%d", id)
|
||||
}
|
||||
Reference in new issue
Block a user