@@ -12,6 +12,11 @@ import (
1212
1313const dttmLayout = "2006-01-02"
1414
15+ var (
16+ addressLookup = aklapi .AddressLookup
17+ collectionDayDetail = aklapi .CollectionDayDetail
18+ )
19+
1520type rrResponse struct {
1621 Rubbish string `json:"rubbish,omitempty"`
1722 Recycle string `json:"recycle,omitempty"`
@@ -24,6 +29,7 @@ func respond(w http.ResponseWriter, data any, code int) {
2429 b , err := json .Marshal (data )
2530 if err != nil {
2631 http .Error (w , err .Error (), http .StatusInternalServerError )
32+ return
2733 }
2834 w .Header ().Set ("Content-Type" , "application/json; charset=UTF-8" )
2935 w .WriteHeader (code )
@@ -35,7 +41,7 @@ func rubbish(r *http.Request) (*aklapi.CollectionDayDetailResult, error) {
3541 if addr == "" {
3642 return nil , errors .New (http .StatusText (http .StatusBadRequest ))
3743 }
38- return aklapi . CollectionDayDetail (r .Context (), addr )
44+ return collectionDayDetail (r .Context (), addr )
3945}
4046
4147func addrHandler (w http.ResponseWriter , r * http.Request ) {
@@ -44,10 +50,10 @@ func addrHandler(w http.ResponseWriter, r *http.Request) {
4450 http .Error (w , http .StatusText (http .StatusBadRequest ), http .StatusBadRequest )
4551 return
4652 }
47- resp , err := aklapi . AddressLookup (r .Context (), addr )
53+ resp , err := addressLookup (r .Context (), addr )
4854 if err != nil {
4955 slog .Error ("address lookup failed" , "error" , err )
50- http .NotFound (w , r )
56+ http .Error (w , http . StatusText ( http . StatusBadGateway ), http . StatusBadGateway )
5157 return
5258 }
5359 respond (w , resp , http .StatusOK )
0 commit comments