-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
52 lines (42 loc) · 948 Bytes
/
config.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
package receiptscanner
import (
"context"
//"errors"
"log"
//"os"
"cloud.google.com/go/storage"
"cloud.google.com/go/datastore"
)
var (
DB ReceiptDatabase
StorageBucket *storage.BucketHandle
StorageBucketName string
)
func init() {
var err error
DB, err = configureDatastoreDB("receiptscanner-0")
if err != nil {
log.Fatal(err)
}
StorageBucketName = "receiptscanner-0.appspot.com"
StorageBucket, err = configureStorage(StorageBucketName)
if err != nil {
log.Fatal(err)
}
}
func configureDatastoreDB(projectID string) (ReceiptDatabase, error) {
ctx := context.Background()
client, err := datastore.NewClient(ctx, projectID)
if err != nil {
return nil, err
}
return newDatastoreDB(client)
}
func configureStorage(bucketID string) (*storage.BucketHandle, error) {
ctx := context.Background()
client, err := storage.NewClient(ctx)
if err != nil {
return nil, err
}
return client.Bucket(bucketID), nil
}