mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-27 10:47:06 +02:00
added logout endpoint
This commit is contained in:
@@ -29,6 +29,8 @@ func NewHandler() http.Handler {
|
|||||||
// mux.HandleFunc("GET", "/v1/checkhealth", v1.CheckHealth)
|
// mux.HandleFunc("GET", "/v1/checkhealth", v1.CheckHealth)
|
||||||
// mux.HandleFunc("HEAD", "/v1/checkhealth", v1.CheckHealth)
|
// mux.HandleFunc("HEAD", "/v1/checkhealth", v1.CheckHealth)
|
||||||
mux.HandleFunc("POST", "/v1/login", auth.LoginHandler)
|
mux.HandleFunc("POST", "/v1/login", auth.LoginHandler)
|
||||||
|
mux.HandleFunc("GET", "/v1/logout", auth.LogoutHandler)
|
||||||
|
mux.HandleFunc("POST", "/v1/logout", auth.LogoutHandler)
|
||||||
mux.HandleFunc("POST", "/v1/reload", v1.Reload)
|
mux.HandleFunc("POST", "/v1/reload", v1.Reload)
|
||||||
mux.HandleFunc("GET", "/v1/list", auth.RequireAuth(v1.List))
|
mux.HandleFunc("GET", "/v1/list", auth.RequireAuth(v1.List))
|
||||||
mux.HandleFunc("GET", "/v1/list/{what}", auth.RequireAuth(v1.List))
|
mux.HandleFunc("GET", "/v1/list/{what}", auth.RequireAuth(v1.List))
|
||||||
|
|||||||
@@ -80,6 +80,19 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.SetCookie(w, &http.Cookie{
|
||||||
|
Name: "token",
|
||||||
|
Value: "",
|
||||||
|
Expires: time.Unix(0, 0),
|
||||||
|
HttpOnly: true,
|
||||||
|
SameSite: http.SameSiteStrictMode,
|
||||||
|
Path: "/",
|
||||||
|
})
|
||||||
|
w.Header().Set("location", "/login")
|
||||||
|
w.WriteHeader(http.StatusTemporaryRedirect)
|
||||||
|
}
|
||||||
|
|
||||||
func RequireAuth(next http.HandlerFunc) http.HandlerFunc {
|
func RequireAuth(next http.HandlerFunc) http.HandlerFunc {
|
||||||
if common.IsDebugSkipAuth {
|
if common.IsDebugSkipAuth {
|
||||||
return next
|
return next
|
||||||
|
|||||||
12
internal/net/http/middleware/rate_limiter.go
Normal file
12
internal/net/http/middleware/rate_limiter.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
type (
|
||||||
|
rateLimiter struct {
|
||||||
|
*rateLimiterOpts
|
||||||
|
m *Middleware
|
||||||
|
}
|
||||||
|
|
||||||
|
rateLimiterOpts struct {
|
||||||
|
Count int `json:"count"`
|
||||||
|
}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user