-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (47 loc) · 1.12 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
package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
// Version is program version
var Version = "development"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.GET("/version", func(c *gin.Context) {
c.JSON(200, gin.H{
"version": fmt.Sprintf("%s", Version),
})
})
r.GET("/metrics", gin.WrapH(promhttp.Handler()))
r.POST("/v2/enqueue", func(c *gin.Context) {
buf := make([]byte, 2048)
n, _ := c.Request.Body.Read(buf)
b := string(buf[0:n])
fmt.Println(b)
num := len(b)
switch {
case num == 0:
c.JSON(http.StatusBadRequest, gin.H{
"status": "invalid event",
"message": "Event object is invalid",
"errors": "Length of 'routing_key' is incorrect (should be 32 characters)",
})
case num > 500:
c.AbortWithStatus(http.StatusTooManyRequests)
default:
c.JSON(http.StatusAccepted, gin.H{
"status": "success",
"message": "Event processed",
"dedup_key": "samplekeyhere",
})
}
})
r.Run() // listen and serve on 0.0.0.0:8080
}