39 lines
948 B
Go
39 lines
948 B
Go
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func main() {
|
|
handleRoute()
|
|
}
|
|
|
|
func handleRoute() {
|
|
// Раздача статических файлов (CSS, JS, изображения и т.д.)
|
|
fs := http.FileServer(http.Dir("static"))
|
|
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
|
|
|
http.HandleFunc("/auth", auth)
|
|
log.Println("Server is running on port 8080...")
|
|
err := http.ListenAndServe(":8080", nil)
|
|
if err != nil {
|
|
log.Fatalf("Server failed to start: %v", err)
|
|
}
|
|
}
|
|
|
|
func auth(w http.ResponseWriter, r *http.Request) {
|
|
tmpl, err := template.ParseFiles("templates/auth.html")
|
|
if err != nil {
|
|
http.Error(w, "Error parsing template", http.StatusInternalServerError)
|
|
log.Printf("Error loading template: %v", err)
|
|
return
|
|
}
|
|
err = tmpl.Execute(w, nil)
|
|
if err != nil {
|
|
http.Error(w, "Error executing template", http.StatusInternalServerError)
|
|
log.Printf("Error executing template: %v", err)
|
|
}
|
|
}
|