-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (51 loc) · 1.77 KB
/
main.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
package main
import (
"context"
"fmt"
"os"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var MONGODB_URI string = os.Getenv("MONGODB_URI")
var mongoClient *mongo.Client
func connect_to_mongodb() {
fmt.Println("Connecting to MongoDB...")
fmt.Println("MONGODB_URI: len=", len(MONGODB_URI))
serverAPI := options.ServerAPI(options.ServerAPIVersion1)
opts := options.Client().ApplyURI(MONGODB_URI).SetServerAPIOptions(serverAPI).SetAppName("solar-tracker").SetCompressors([]string{"zstd", "zlib", "snappy"})
fmt.Println("AppName: ", *opts.AppName)
fmt.Println("Compressors: ", opts.Compressors)
client, err := mongo.Connect(context.TODO(), opts)
if err != nil {
panic(err)
}
err = client.Ping(context.TODO(), nil)
if err != nil {
panic(err)
}
mongoClient = client
fmt.Println("Connected to MongoDB!")
}
func init() {
connect_to_mongodb()
}
func main() {
r := gin.Default()
r.Use(gzip.Gzip(gzip.NoCompression, gzip.WithOnlyDecompress(true), gzip.WithDecompressFn(gzip.DefaultDecompressHandle)))
r.GET("/ping", ping)
r.HEAD("/ping", ping)
r.GET("/ping_mongodb", ping_mongodb)
r.HEAD("/ping_mongodb", ping_mongodb)
v1_tracker := r.Group("/v1")
{
v1_tracker.POST("/projects", v1_projects)
v1_tracker.POST("/project/:identifier", v1_project)
v1_tracker.POST("/project/:identifier/:client_version/:archivist/claim_task", v1_claim_task)
v1_tracker.POST("/project/:identifier/:client_version/:archivist/update_task/:task_id", v1_update_task)
v1_tracker.POST("/project/:identifier/:client_version/:archivist/insert_item/:item_id", v1_insert_item)
v1_tracker.POST("/project/:identifier/:client_version/:archivist/insert_many/:size", v1_insert_many) // :size unused
}
r.Run()
}