feat(go): implement server to parse address

This commit is contained in:
Joao P Dubas
2024-01-29 12:31:04 +00:00
parent d355f46856
commit 1b96d3aebc
5 changed files with 214 additions and 5 deletions

View File

@@ -1,12 +1,25 @@
package main
import (
"fmt"
parser "github.com/openvenues/gopostal/parser"
"html/template"
"log"
"net/http"
)
func main() {
addressComponents := parser.ParseAddress("rua pedroso xavier 277, apto 51 torre 2. vila albertina, 02732-020, são paulo, sp, brasil")
fmt.Println(addressComponents)
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))
}