feat(go): implement server to parse address
This commit is contained in:
23
go/main.go
23
go/main.go
@@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user