-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 900 Bytes
/
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
// Copyright Fauna, Inc.
// SPDX-License-Identifier: MIT-0
package main
import (
"net/http"
"os"
"github/fauna-labs/go-gin-fly-io-starter/internal/utils"
"github.com/fauna/fauna-go"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
client := fauna.NewClient(os.Getenv("FAUNA_SECRET_KEY"), fauna.DefaultTimeouts())
r.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"greeting": "Hello go-gin-fly-io-starter"})
})
r.GET("/read", func(c *gin.Context) {
q, _ := fauna.FQL(`
order.all() {
orderName: .name,
customer: .customer.firstName + " " + .customer.lastName,
orderProducts {
product: .product.name,
price,
quantity
}
}
`, nil)
res, err := client.Query(q)
if err != nil {
s := utils.GetErrorResponseStatusCode(err)
c.JSON(s, err)
} else {
c.JSON(http.StatusOK, utils.GenerateResponse(res))
}
})
r.Run()
}