use embed and new mux
This commit is contained in:
8
klice.go
8
klice.go
@@ -66,7 +66,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
http.ServeFile(w, r, "templates/login.html")
|
http.ServeFileFS(w, r, templatesFS, "templates/login.html")
|
||||||
default:
|
default:
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
@@ -146,8 +146,8 @@ func teamInfoHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func qrHandler(w http.ResponseWriter, r *http.Request) {
|
func qrHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
uid, found := strings.CutPrefix(r.URL.Path, "/qr/")
|
uid := r.PathValue("qr")
|
||||||
if !found || uid == "" {
|
if uid == "" {
|
||||||
http.Error(w, "Invalid QR code", http.StatusBadRequest)
|
http.Error(w, "Invalid QR code", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ func main() {
|
|||||||
http.HandleFunc("/admin/levels", AdminLevelHandler)
|
http.HandleFunc("/admin/levels", AdminLevelHandler)
|
||||||
http.HandleFunc("/admin/cipher", AdminCipherHandler)
|
http.HandleFunc("/admin/cipher", AdminCipherHandler)
|
||||||
http.HandleFunc("/admin/positions", AdminPositionsHandler)
|
http.HandleFunc("/admin/positions", AdminPositionsHandler)
|
||||||
http.HandleFunc("/admin/qr", AdminQRHandler)
|
http.HandleFunc("/admin/qr/{qr...}", AdminQRHandler)
|
||||||
http.HandleFunc("/admin/penalties", AdminPenaltiesHandler)
|
http.HandleFunc("/admin/penalties", AdminPenaltiesHandler)
|
||||||
|
|
||||||
// static files
|
// static files
|
||||||
|
|||||||
22
templates.go
22
templates.go
@@ -1,9 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"html/template"
|
"html/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed templates/*.html
|
||||||
|
var templatesFS embed.FS
|
||||||
|
|
||||||
type CipherTemplateS struct {
|
type CipherTemplateS struct {
|
||||||
ID int
|
ID int
|
||||||
Order uint
|
Order uint
|
||||||
@@ -86,12 +90,12 @@ type AdminPenaltiesTemplateS struct {
|
|||||||
Minutes int
|
Minutes int
|
||||||
}
|
}
|
||||||
|
|
||||||
var CipherTemplate = template.Must(template.ParseFiles("templates/assignment.html"))
|
var CipherTemplate = template.Must(template.ParseFS(templatesFS, "templates/assignment.html"))
|
||||||
var TeamTemplate = template.Must(template.ParseFiles("templates/team.html"))
|
var TeamTemplate = template.Must(template.ParseFS(templatesFS, "templates/team.html"))
|
||||||
var AdminTeamsTemplate = template.Must(template.ParseFiles("templates/adminTeams.html"))
|
var AdminTeamsTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminTeams.html"))
|
||||||
var AdminRoutesTemplate = template.Must(template.ParseFiles("templates/adminRoutes.html"))
|
var AdminRoutesTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminRoutes.html"))
|
||||||
var AdminLevelTemplate = template.Must(template.ParseFiles("templates/adminLevels.html"))
|
var AdminLevelTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminLevels.html"))
|
||||||
var AdminCipherTemplate = template.Must(template.ParseFiles("templates/adminCiphers.html"))
|
var AdminCipherTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminCiphers.html"))
|
||||||
var AdminPositionsTemplate = template.Must(template.ParseFiles("templates/adminPositions.html"))
|
var AdminPositionsTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminPositions.html"))
|
||||||
var AdminQRsTemplate = template.Must(template.ParseFiles("templates/adminQR.html"))
|
var AdminQRsTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminQR.html"))
|
||||||
var AdminPenaltiesTemplate = template.Must(template.ParseFiles("templates/adminPenalties.html"))
|
var AdminPenaltiesTemplate = template.Must(template.ParseFS(templatesFS, "templates/adminPenalties.html"))
|
||||||
|
|||||||
Reference in New Issue
Block a user