Initial commit

This commit is contained in:
2025-09-06 21:35:45 -04:00
commit b02525e28a
32 changed files with 1478 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package controllers
import (
"addrss/pkg/router"
"fmt"
expand "github.com/openvenues/gopostal/expand"
parser "github.com/openvenues/gopostal/parser"
)
type Api struct{}
type ParseRequest struct {
Address string `json:"address"`
}
func (a Api) AddRoutes() {
router.AddPost("/v1/expand", expandAddress).Anonymous()
router.AddPost("/v1/parse", parseAddress).Anonymous()
}
func expandAddress(ctx *router.Context) {
expansions := expand.ExpandAddress("1080 Brayden Ct. Hebron KY 41048")
for i := 0; i < len(expansions); i++ {
fmt.Println(expansions[i])
}
ctx.Response.NoContent()
}
func parseAddress(ctx *router.Context) {
pr := ParseRequest{}
if err := ctx.Request.Bind(&pr); err != nil {
ctx.Response.BadRequest(err)
}
options := parser.ParserOptions{}
pa := parser.ParseAddressOptions(pr.Address, options)
addr := map[string]any{}
for i := 0; i < len(pa); i++ {
addr[pa[i].Label] = pa[i].Value
}
ctx.Response.OK(addr)
}