Files
AstralCalendar/webserver/webserver.go
T

40 lines
887 B
Go

package webserver
import (
"fmt"
"net/http"
)
var routes []string
func ServeLoginPage(route string) {
ServeWebpage(route, loginHandler)
}
func EnableLogoRoute() {
ServeWebpage("/logo", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "webserver/images/astraltech_logo.png")
})
ServeWebpage("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "webserver/images/astraltech_favicon.png")
})
}
func EnableStaticRoute() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("webserver/static"))))
routes = append(routes, "/static/*")
}
func ServeWebpage(url string, handler func(http.ResponseWriter, *http.Request)) {
http.HandleFunc(url, handler)
routes = append(routes, url)
}
func ServeWebserver() {
err := http.ListenAndServe(":8080", nil)
if err != nil {
fmt.Print(err.Error())
}
}