-
Notifications
You must be signed in to change notification settings - Fork 1
/
mystop.go
42 lines (35 loc) · 793 Bytes
/
mystop.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
package nyctraintime
import (
"context"
"cloud.google.com/go/datastore"
)
type myStop struct {
Line string
Stop string
Dir string
}
type db struct {
db *datastore.Client
}
func newDB(ctx context.Context, project string) (*db, error) {
client, err := datastore.NewClient(ctx, project)
if err != nil {
return nil, err
}
return &db{db: client}, nil
}
func (d *db) getMyStop(ctx context.Context, userID string) (*myStop, error) {
var my myStop
key := datastore.NameKey("MyStop", userID, nil)
err := d.db.Get(ctx, key, &my)
return &my, err
}
func (d *db) saveMyStop(ctx context.Context, userID, line, stop, dir string) error {
key := datastore.NameKey("MyStop", userID, nil)
_, err := d.db.Put(ctx, key, &myStop{
Line: line,
Stop: stop,
Dir: dir,
})
return err
}