-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use constants for all flags; support plain old leaflet tiles; add /da…
…ta endpoint
- Loading branch information
thisisaaronland
committed
Mar 23, 2021
1 parent
f34107c
commit d4474e4
Showing
12 changed files
with
249 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package http | ||
|
||
// TBD: make this part of whosonfirst/go-reader package... | ||
|
||
import ( | ||
"github.com/whosonfirst/go-reader" | ||
"github.com/whosonfirst/go-whosonfirst-uri" | ||
"io" | ||
gohttp "net/http" | ||
) | ||
|
||
func NewDataHandler(r reader.Reader) (gohttp.Handler, error) { | ||
|
||
fn := func(rsp gohttp.ResponseWriter, req *gohttp.Request) { | ||
|
||
path := req.URL.Path | ||
|
||
id, uri_args, err := uri.ParseURI(path) | ||
|
||
if err != nil { | ||
gohttp.Error(rsp, err.Error(), gohttp.StatusBadRequest) | ||
return | ||
} | ||
|
||
rel_path, err := uri.Id2RelPath(id, uri_args) | ||
|
||
if err != nil { | ||
gohttp.Error(rsp, err.Error(), gohttp.StatusBadRequest) | ||
return | ||
} | ||
|
||
ctx := req.Context() | ||
fh, err := r.Read(ctx, rel_path) | ||
|
||
if err != nil { | ||
gohttp.Error(rsp, err.Error(), gohttp.StatusBadRequest) | ||
return | ||
} | ||
|
||
rsp.Header().Set("Content-Type", "application/json") | ||
|
||
_, err = io.Copy(rsp, fh) | ||
|
||
if err != nil { | ||
gohttp.Error(rsp, err.Error(), gohttp.StatusBadRequest) | ||
return | ||
} | ||
|
||
return | ||
} | ||
|
||
h := gohttp.HandlerFunc(fn) | ||
return h, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.