This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
forked from crolly/dyngeo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo.go
76 lines (60 loc) · 2.01 KB
/
geo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package dyngeo
import (
"context"
)
type Geo struct {
db db
q querier
unmarshalAsJSON bool
}
func New(cfg *Config) (*Geo, error) {
if err := cfg.Valid(); err != nil {
return nil, err
}
db := newDB(*cfg)
g := &Geo{
unmarshalAsJSON: cfg.unmarshalAsJSON,
db: db,
q: newQuerier(*cfg, db),
}
return g, nil
}
func (g Geo) GetPoint(ctx context.Context, input GetPointInput) (*GetPointOutput, error) {
return g.db.getPoint(ctx, input)
}
func (g Geo) QueryRadius(ctx context.Context, input QueryRadiusInput, out interface{}) error {
output, err := g.q.QueryRadius(ctx, input)
if err != nil {
return err
}
return queryResponse(output).Unmarshal(g.unmarshalAsJSON, out)
}
func (g Geo) QueryRectangle(ctx context.Context, input QueryRectangleInput, out interface{}) error {
output, err := g.q.QueryRectangle(ctx, input)
if err != nil {
return err
}
return queryResponse(output).Unmarshal(g.unmarshalAsJSON, out)
}
func (g Geo) QueryRadiusPaginated(ctx context.Context, input QueryRadiusInput, hashToLastEvaluatedEntry GeoHashToLastEvaluatedDBValue, limit uint, out interface{}) (GeoHashToLastEvaluatedDBValue, error) {
if limit == 0 {
return nil, ErrPaginatedQueryInvalidLimit{}
}
output, newHashToLEntry, err := g.q.QueryRadiusWithPagination(ctx, input, hashToLastEvaluatedEntry, limit)
if err != nil {
return nil, err
}
return newHashToLEntry, queryResponse(output).Unmarshal(g.unmarshalAsJSON, out)
}
func (g Geo) PutPoint(ctx context.Context, input PutPointInput) (*PutPointOutput, error) {
return g.db.putPoint(ctx, input)
}
func (g Geo) BatchWritePoints(ctx context.Context, inputs []PutPointInput) (*BatchWritePointOutput, error) {
return g.db.batchWritePoints(ctx, inputs)
}
func (g Geo) UpdatePoint(ctx context.Context, input UpdatePointInput) (*UpdatePointOutput, error) {
return g.db.updatePoint(ctx, input)
}
func (g Geo) DeletePoint(ctx context.Context, input DeletePointInput) (*DeletePointOutput, error) {
return g.db.deletePoint(ctx, input)
}