-
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.
update vendor deps; move guts of code cmd/ tools in to app/
- Loading branch information
sfomuseumbot
committed
Dec 8, 2022
1 parent
6d1b85e
commit 0af21c1
Showing
592 changed files
with
56,123 additions
and
31,308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"github.com/sfomuseum/go-flags/flagset" | ||
"github.com/sfomuseum/go-flags/lookup" | ||
grpc_flags "github.com/whosonfirst/go-whosonfirst-spatial-grpc/flags" | ||
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/request" | ||
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/spatial" | ||
spatial_flags "github.com/whosonfirst/go-whosonfirst-spatial/flags" | ||
"google.golang.org/grpc" | ||
"io" | ||
"log" | ||
"os" | ||
) | ||
|
||
func Run(ctx context.Context, logger *log.Logger) error { | ||
|
||
fs, err := DefaultFlagSet() | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to create default flagset, %w", err) | ||
} | ||
|
||
return RunWithFlagSet(ctx, fs, logger) | ||
} | ||
|
||
func RunWithFlagSet(ctx context.Context, fs *flag.FlagSet, logger *log.Logger) error { | ||
|
||
flagset.Parse(fs) | ||
|
||
err := grpc_flags.ValidateGRPCClientFlags(fs) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to validate grpc client flags, %w", err) | ||
} | ||
|
||
err = spatial_flags.ValidateQueryFlags(fs) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to validate query flags, %w", err) | ||
} | ||
|
||
req, err := request.NewPointInPolygonRequestFromFlagSet(fs) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to create PIP request, %v", err) | ||
} | ||
|
||
host, _ := lookup.StringVar(fs, grpc_flags.HOST) | ||
port, _ := lookup.IntVar(fs, grpc_flags.PORT) | ||
|
||
var opts []grpc.DialOption | ||
opts = append(opts, grpc.WithInsecure()) | ||
|
||
addr := fmt.Sprintf("%s:%d", host, port) | ||
|
||
conn, err := grpc.Dial(addr, opts...) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to dial '%s', %v", addr, err) | ||
} | ||
|
||
defer conn.Close() | ||
|
||
client := spatial.NewSpatialClient(conn) | ||
|
||
stream, err := client.PointInPolygon(ctx, req) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to perform point in polygon operation, %w", err) | ||
} | ||
|
||
to_stdout, _ := lookup.BoolVar(fs, grpc_flags.TO_STDOUT) | ||
to_null, _ := lookup.BoolVar(fs, grpc_flags.TO_NULL) | ||
|
||
writers := make([]io.Writer, 0) | ||
|
||
if to_stdout { | ||
writers = append(writers, os.Stdout) | ||
} | ||
|
||
if to_null { | ||
writers = append(writers, io.Discard) | ||
} | ||
|
||
wr := io.MultiWriter(writers...) | ||
|
||
enc := json.NewEncoder(wr) | ||
err = enc.Encode(stream) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failed to encode stream, %v", err) | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package client | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/sfomuseum/go-flags/flagset" | ||
grpc_flags "github.com/whosonfirst/go-whosonfirst-spatial-grpc/flags" | ||
spatial_flags "github.com/whosonfirst/go-whosonfirst-spatial/flags" | ||
) | ||
|
||
func DefaultFlagSet() (*flag.FlagSet, error) { | ||
|
||
fs := flagset.NewFlagSet("client") | ||
|
||
err := grpc_flags.AppendGRPCClientFlags(fs) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed to append grpc client flags, %w", err) | ||
} | ||
|
||
err = spatial_flags.AppendQueryFlags(fs) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed to append query flags, %w", err) | ||
} | ||
|
||
return fs, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package server | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
grpc_flags "github.com/whosonfirst/go-whosonfirst-spatial-grpc/flags" | ||
spatial_flags "github.com/whosonfirst/go-whosonfirst-spatial/flags" | ||
) | ||
|
||
func DefaultFlagSet() (*flag.FlagSet, error) { | ||
|
||
fs, err := spatial_flags.CommonFlags() | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed to create common flags, %v", err) | ||
} | ||
|
||
err = spatial_flags.AppendIndexingFlags(fs) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed to append indexing flags, %v", err) | ||
} | ||
|
||
err = grpc_flags.AppendGRPCServerFlags(fs) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("Failed to append server flags, %v", err) | ||
} | ||
|
||
return fs, 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
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 |
---|---|---|
@@ -1,28 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
_ "github.com/whosonfirst/go-whosonfirst-spatial-rtree" | ||
) | ||
|
||
import ( | ||
"context" | ||
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/server" | ||
"github.com/whosonfirst/go-whosonfirst-spatial-grpc/app/server" | ||
"log" | ||
) | ||
|
||
func main() { | ||
|
||
ctx := context.Background() | ||
logger := log.Default() | ||
|
||
app, err := server.NewServerApplication() | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to create new server application, %v", err) | ||
} | ||
|
||
err = app.Run(ctx) | ||
err := server.Run(ctx, logger) | ||
|
||
if err != nil { | ||
log.Fatalf("Failed to run server application, %v", err) | ||
logger.Fatalf("Failed to run client, %v", err) | ||
} | ||
} |
Oops, something went wrong.