Initial commit: VPN panel on Go, PostgreSQL 17, Docker, Xray-core

This commit is contained in:
vpn-panel
2026-05-21 18:55:14 +03:00
commit 3c2f5226d1
27 changed files with 1778 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package handlers
import (
"net/http"
)
const flashCookie = "vpn_panel_flash"
func flashSet(w http.ResponseWriter, msg, level string) {
http.SetCookie(w, &http.Cookie{
Name: flashCookie,
Value: level + ":" + msg,
Path: "/",
MaxAge: 30,
HttpOnly: true,
SameSite: http.SameSiteLaxMode,
})
}
func flashGet(w http.ResponseWriter, r *http.Request) map[string]string {
c, err := r.Cookie(flashCookie)
if err != nil {
return nil
}
http.SetCookie(w, &http.Cookie{Name: flashCookie, Path: "/", MaxAge: -1})
parts := splitFlash(c.Value)
if len(parts) != 2 {
return nil
}
return map[string]string{"Level": parts[0], "Message": parts[1]}
}
func splitFlash(v string) []string {
for i := 0; i < len(v); i++ {
if v[i] == ':' {
return []string{v[:i], v[i+1:]}
}
}
return nil
}