You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
56 lines
1.9 KiB
package main |
|
|
|
import ( |
|
"log" |
|
"net/http" |
|
"text/template" |
|
) |
|
|
|
type TemplateData struct { |
|
Title string |
|
Description string |
|
URL string |
|
IncludeServiceWorker bool |
|
} |
|
|
|
func main() { |
|
mainTemplate, err := template.ParseFiles("./templates/main.tmpl") |
|
if err != nil { |
|
log.Fatal("Error: Unable to parse the template file.") |
|
} |
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { |
|
if req.URL.Path == "/smatter" || req.URL.Path == "/smatter/offline.html" { |
|
data := TemplateData { |
|
Title: "Do Blue Lives Matter?", |
|
Description: "No", |
|
URL: "https://doblue.live/smatter", |
|
IncludeServiceWorker: req.URL.Path == "/smatter", |
|
} |
|
|
|
mainTemplate.Execute(w, data) |
|
} else if req.URL.Path == "/sreallymatter" || req.URL.Path == "/sreallymatter/offline.html" { |
|
data := TemplateData { |
|
Title: "Do Blue Lives Really Matter?", |
|
Description: "Still No", |
|
URL: "https://doblue.live/sreallymatter", |
|
IncludeServiceWorker: req.URL.Path == "/sreallymatter", |
|
} |
|
|
|
mainTemplate.Execute(w, data) |
|
} else if req.URL.Path == "/robots.txt" { |
|
http.ServeFile(w, req, "./static/robots.txt") |
|
} else if req.URL.Path == "/service-worker.js" { |
|
http.ServeFile(w, req, "./static/service-worker.js") |
|
} else { |
|
scheme := "http" |
|
if req.TLS != nil { |
|
scheme += "s" |
|
} |
|
|
|
http.Redirect(w, req, scheme + "://" + req.Host + "/smatter", http.StatusPermanentRedirect) |
|
} |
|
}) |
|
|
|
log.Fatal(http.ListenAndServe(":8081", nil)) |
|
} |