Skip to content

Commit

Permalink
add local grpc-client
Browse files Browse the repository at this point in the history
  • Loading branch information
sfomuseumbot committed Jul 19, 2024
1 parent 0811b25 commit cc81341
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 41 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LDFLAGS=-s -w
cli:
go build -ldflags="$(LDFLAGS)" -mod $(GOMOD) -o bin/http-server cmd/http-server/main.go
go build -ldflags="$(LDFLAGS)" -mod $(GOMOD) -o bin/grpc-server cmd/grpc-server/main.go
go build -ldflags="$(LDFLAGS)" -mod $(GOMOD) -o bin/grpc-client cmd/grpc-client/main.go
go build -ldflags="$(LDFLAGS)" -mod $(GOMOD) -o bin/update-hierarchies cmd/update-hierarchies/main.go
go build -ldflags="$(LDFLAGS)" -mod $(GOMOD) -o bin/pip cmd/pip/main.go

Expand All @@ -14,3 +15,7 @@ httpd:
go run cmd/http-server/main.go \
-enable-www \
-spatial-database-uri "sqlite://?dsn=$(DSN)"

grpcd:
go run cmd/grpc-server/main.go \
'sqlite://?dsn=$(DSN)'
129 changes: 94 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ Here's an example of the creating a compatible SQLite database for all the [admi
```
$> ./bin/wof-sqlite-index-features \
-index-alt-files \
-rtree \
-spr \
-properties \
-spatial-tables \
-timings \
-dsn /usr/local/ca-alt.db \
-mode repo:// \
Expand Down Expand Up @@ -381,36 +379,10 @@ $> go run -mod vendor cmd/query/main.go \

_Big thanks to @psanford 's [sqlitevfshttp](https://github.com/psanford/sqlite3vfshttp) package for making this possible._

## Interfaces

This package implements the following [go-whosonfirst-spatial](#) interfaces.

### spatial.SpatialDatabase

```
import (
"github.com/whosonfirst/go-whosonfirst-spatial/database"
_ "github.com/whosonfirst/go-whosonfirst-spatial-sqlite"
)
db, err := database.NewSpatialDatabase(ctx, "sqlite://?dsn={DSN}")
```

### spatial.PropertiesReader

```
import (
"github.com/whosonfirst/go-whosonfirst-spatial/properties"
_ "github.com/whosonfirst/go-whosonfirst-spatial-sqlite"
)
### http-server

pr, err := properties.NewPropertiesReader(ctx, "sqlite://?dsn={DSN}")
```

## server

```
> ./bin/server -h
> ./bin/http-server -h
-authenticator-uri string
A valid sfomuseum/go-http-auth URI. (default "null://")
-cors-allow-credentials
Expand Down Expand Up @@ -466,7 +438,7 @@ pr, err := properties.NewPropertiesReader(ctx, "sqlite://?dsn={DSN}")
For example:

```
$> bin/server \
$> bin/http-server \
-enable-www \
-spatial-database-uri 'sqlite:///?dsn=modernc:///usr/local/data/sfomuseum-data-architecture.db'
```
Expand All @@ -482,7 +454,7 @@ When you visit `http://localhost:8080` in your web browser you should see someth
If you don't need, or want, to expose a user-facing interface simply remove the `-enable-www` and `-nextzen-apikey` flags. For example:

```
$> bin/server \
$> bin/http-server \
-spatial-database-uri 'sqlite:///?dsn=modernc:///usr/local/data/sfomuseum-data-architecture.db'
```

Expand Down Expand Up @@ -527,7 +499,7 @@ By default, results are returned as a list of ["standard places response"](https


```
$> bin/server \
$> bin/http-server \
-enable-geojson \
-spatial-database-uri 'sqlite:///?dsn=modernc:///usr/local/data/sfomuseum-data-architecture.db'
```
Expand Down Expand Up @@ -578,10 +550,97 @@ $> curl -s -XPOST -H 'Accept: application/geo+json' 'http://localhost:8080/api/p
}
```

### grpc-server

```
$> ./bin/grpc-server -h
-custom-placetypes string
A JSON-encoded string containing custom placetypes defined using the syntax described in the whosonfirst/go-whosonfirst-placetypes repository.
-enable-custom-placetypes
Enable wof:placetype values that are not explicitly defined in the whosonfirst/go-whosonfirst-placetypes repository.
-host string
The host to listen for requests on (default "localhost")
-is-wof
Input data is WOF-flavoured GeoJSON. (Pass a value of '0' or 'false' if you need to index non-WOF documents. (default true)
-iterator-uri string
A valid whosonfirst/go-whosonfirst-iterate/v2 URI. Supported schemes are: directory://, featurecollection://, file://, filelist://, geojsonl://, null://, repo://. (default "repo://")
-port int
The port to listen for requests on (default 8082)
-properties-reader-uri string
A valid whosonfirst/go-reader.Reader URI. Available options are: [fs:// null:// repo:// sqlite:// stdin://]. If the value is {spatial-database-uri} then the value of the '-spatial-database-uri' implements the reader.Reader interface and will be used.
-spatial-database-uri string
A valid whosonfirst/go-whosonfirst-spatial/data.SpatialDatabase URI. options are: [rtree:// sqlite://] (default "rtree://")
```

For example:

```
$> ./bin/grpc-server -spatial-database-uri 'sqlite://?dsn=modernc:///usr/local/data/arch.db'
2024/07/19 10:52:47 Listening on localhost:8082
```

And then in another terminal:

```
$> ./bin/grpc-client -latitude 37.621131 -longitude -122.384292 | jq '.places[]["name"]'
"San Francisco International Airport"
```

### grpc-client

```
$> ./bin/grpc-client -h
-alternate-geometry value
One or more alternate geometry labels (wof:alt_label) values to filter results by.
-cessation string
A valid EDTF date string.
-geometries string
Valid options are: all, alt, default. (default "all")
-host string
The host of the gRPC server to connect to. (default "localhost")
-inception string
A valid EDTF date string.
-is-ceased value
One or more existential flags (-1, 0, 1) to filter results by.
-is-current value
One or more existential flags (-1, 0, 1) to filter results by.
-is-deprecated value
One or more existential flags (-1, 0, 1) to filter results by.
-is-superseded value
One or more existential flags (-1, 0, 1) to filter results by.
-is-superseding value
One or more existential flags (-1, 0, 1) to filter results by.
-latitude float
A valid latitude.
-longitude float
A valid longitude.
-null
Emit results to /dev/null
-placetype value
One or more place types to filter results by.
-port int
The port of the gRPC server to connect to. (default 8082)
-property value
One or more Who's On First properties to append to each result.
-sort-uri value
Zero or more whosonfirst/go-whosonfirst-spr/sort URIs.
-stdout
Emit results to STDOUT (default true)
```

For example:

```
$> ./bin/grpc-client -latitude 37.621131 -longitude -122.384292 | jq '.places[]["name"]'
"San Francisco International Airport"
```

## See also

* https://www.sqlite.org/rtree.html
* https://github.com/whosonfirst/go-whosonfirst-spatial
* https://github.com/whosonfirst/go-whosonfirst-spatial-www
* https://github.com/whosonfirst/go-whosonfirst-spatial-grpc
* https://github.com/whosonfirst/go-whosonfirst-sqlite
* https://github.com/whosonfirst/go-whosonfirst-sqlite-features
* https://github.com/whosonfirst/go-whosonfirst-sqlite-features-index
* https://github.com/whosonfirst/go-reader
20 changes: 20 additions & 0 deletions cmd/grpc-client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"context"
"log"

"github.com/whosonfirst/go-whosonfirst-spatial-grpc/app/client"
)

func main() {

ctx := context.Background()
logger := log.Default()

err := client.Run(ctx, logger)

if err != nil {
logger.Fatalf("Failed to run client, %v", err)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/whosonfirst/go-ioutil v1.0.2
github.com/whosonfirst/go-reader v1.0.2
github.com/whosonfirst/go-whosonfirst-spatial v0.10.0
github.com/whosonfirst/go-whosonfirst-spatial-grpc v0.1.1
github.com/whosonfirst/go-whosonfirst-spatial-grpc v0.1.2
github.com/whosonfirst/go-whosonfirst-spatial-www v0.2.0
github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.7
github.com/whosonfirst/go-whosonfirst-sqlite-features/v2 v2.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ github.com/whosonfirst/go-whosonfirst-sources v0.1.0 h1:JuKLa6KWke22jBfJ1pM9WQHo
github.com/whosonfirst/go-whosonfirst-sources v0.1.0/go.mod h1:EUMHyGzUmqPPxlMmOp+28BFeoBdxxE0HCKRd67lkqGM=
github.com/whosonfirst/go-whosonfirst-spatial v0.10.0 h1:l6OwMOy5HazP8vf0EDmgjIGXPPofIX6FHpY/JOX24NE=
github.com/whosonfirst/go-whosonfirst-spatial v0.10.0/go.mod h1:ZYUHliaEMtm3R43ZBTgdRVGhnF92LbrBehUSmR2T7go=
github.com/whosonfirst/go-whosonfirst-spatial-grpc v0.1.1 h1:20MqWjgiWCHIyAhT28PEgMqoBrhwC6lZ4RPdv4DXo1w=
github.com/whosonfirst/go-whosonfirst-spatial-grpc v0.1.1/go.mod h1:giIqrHTO6grd1Geu3gBa2EY2D+GoVSZAY2l9oJYbtRk=
github.com/whosonfirst/go-whosonfirst-spatial-grpc v0.1.2 h1:0a+lES3zv/1iz0ppqMiuLIMxHW+IxO4VTwV7yIo+mw0=
github.com/whosonfirst/go-whosonfirst-spatial-grpc v0.1.2/go.mod h1:giIqrHTO6grd1Geu3gBa2EY2D+GoVSZAY2l9oJYbtRk=
github.com/whosonfirst/go-whosonfirst-spatial-www v0.2.0 h1:LpjuvmBznHQnYbYquo0YPYSJy0dab2sBRP5t6I5A9HU=
github.com/whosonfirst/go-whosonfirst-spatial-www v0.2.0/go.mod h1:yoPKlKjXg0fdRnMuZhcuurn2mBKnN3dMli/4w8TYGas=
github.com/whosonfirst/go-whosonfirst-spr-geojson v0.0.8 h1:K0rCaKo0xvOtuS/x9r62bEfIK3OTdZqbDmgG+A3xDSs=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cc81341

Please sign in to comment.