Files
Advertisement_Panel/main.go
2025-08-28 13:26:16 +02:00

62 lines
1.5 KiB
Go

package main
import (
"Advertisement_Panel/api"
"Advertisement_Panel/config"
"Advertisement_Panel/db"
"fmt"
"html/template"
"net/http"
)
var templates *template.Template
func main() {
templates, _ = template.ParseGlob("website/templates/*.html")
fmt.Print("Now running server!\n")
config.LoadConfig()
db.Init()
// Serves index
http.HandleFunc("/", index_handler)
// Serves json for html to find file names
http.HandleFunc("/files", api.FileHandler)
// Serves ascii page
http.HandleFunc("/ascii", ascii_handler)
// Serves images
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
http.Handle("/uploads/", http.StripPrefix("/uploads/", http.FileServer(http.Dir("./uploads"))))
// Serves administration page
http.HandleFunc("/admin/", admin_handler)
// Handles image upload
http.HandleFunc("/api/upload", api.UploadHandler)
// Handles metadata saving
http.HandleFunc("/api/save-metadata", api.SaveMetadataHandler)
fmt.Print("Webserver running on http://localhost:8080\n")
// Serves what ever the user is requesting base on above urls
http.ListenAndServe(":8080", nil)
}
func index_handler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "images.html", nil)
}
func ascii_handler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "ascii.html", nil)
}
func admin_handler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "admin.html", nil)
}