init from gitlab

This commit is contained in:
texm
2023-04-25 14:33:14 +08:00
parent 6a85a41ff0
commit c8202a5c82
281 changed files with 19861 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
package auth
import (
"net/http"
"time"
)
type authCookieValues struct {
name string
value string
// domain string
httpOnly bool
lifetime time.Duration
}
func makeAuthCookie(values authCookieValues) *http.Cookie {
expiresAt := time.Now().Add(values.lifetime)
cookie := &http.Cookie{
Name: values.name,
Value: values.value,
Expires: expiresAt,
HttpOnly: values.httpOnly,
Path: "/",
// Domain: values.domain,
MaxAge: int(values.lifetime.Seconds()),
Secure: true,
SameSite: http.SameSiteLaxMode,
}
return cookie
}
func clearAuthCookie(name string, httpOnly bool, domain string) *http.Cookie {
vals := authCookieValues{
name: name,
value: "",
// domain: domain,
httpOnly: httpOnly,
lifetime: time.Second,
}
cookie := makeAuthCookie(vals)
return cookie
}