2023-12-01 02:46:50 +00:00

38 lines
658 B
Go

package handlers
import (
"net/http"
"github.com/rs/xid"
"github.com/zhang2092/mediahls/internal/pkg/cookie"
)
const (
AuthorizeCookie = "authorize"
ContextUser CtxTypeUser = "context_user"
)
type CtxTypeUser string
type Authorize struct {
ID string `json:"id"`
Name string `json:"name"`
}
func genId() string {
id := xid.New()
return id.String()
}
func (server *Server) isRedirect(w http.ResponseWriter, r *http.Request) {
_, err := server.withCookie(r)
if err != nil {
// 1. 删除cookie
cookie.DeleteCookie(w, cookie.AuthorizeName)
return
}
// cookie 校验成功
http.Redirect(w, r, "/", http.StatusFound)
}