-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.go
61 lines (49 loc) · 1.05 KB
/
link.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
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"strings"
"cloud.google.com/go/datastore"
"github.com/carvers/linkd/storers"
"google.golang.org/api/option"
)
type stringSlice []string
func (s *stringSlice) String() string {
return strings.Join(*s, ", ")
}
func (s *stringSlice) Set(value string) error {
*s = append(*s, value)
return nil
}
func main() {
ctx := context.Background()
project := os.Getenv("DATASTORE_PROJECT")
creds := os.Getenv("DATASTORE_CREDS")
var client *datastore.Client
var err error
if project == "" {
log.Println("DATASTORE_PROJECT must be set")
os.Exit(1)
}
if creds != "" {
client, err = datastore.NewClient(ctx, project, option.WithServiceAccountFile(creds))
} else {
client, err = datastore.NewClient(ctx, project)
}
if err != nil {
log.Println("Error setting up datastore client:", err.Error())
os.Exit(1)
}
s := server{
datastore: storers.NewDatastore(client),
}
http.Handle("/", &s)
err = http.ListenAndServe(":9876", nil)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}