addressex/go/main.go
2024-01-29 12:31:04 +00:00

26 lines
693 B
Go

package main
import (
"html/template"
"log"
"net/http"
)
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("./templates/index.html"))
tmpl.Execute(w, nil)
})
http.HandleFunc("/parse", func(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("./templates/fragments/results.html"))
data := map[string]Address{"Result": parseAddress(r.URL.Query().Get("address"))}
tmpl.Execute(w, data)
})
log.Println("App running on 9000...")
log.Fatal(http.ListenAndServe(":9000", nil))
}