-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (54 loc) · 1.21 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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
type SpaceStruct struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Type string `json:"type"`
}
type Request struct {
Type string `json:"type"`
Token string `json:"token"`
Space SpaceStruct `json:"space"`
Message struct {
Name string `json:"name"`
Sender struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
AvatarURL string `json:"avatarUrl"`
Email string `json:"email"`
} `json:"sender"`
Text string `json:"text"`
Thread struct {
Name string `json:"name"`
} `json:"thread"`
} `json:"message"`
}
func main() {
r := gin.Default()
r.POST("/", func(c *gin.Context) {
data := &Request{}
response := "Test Default event"
c.Bind(data)
// x,_ := ioutil.ReadAll(c.Request.Body)
fmt.Println(data)
switch eventType := data.Type; eventType {
case "ADDED_TO_SPACE":
response = addToSpace(data.Space)
case "MESSAGE":
response = messageFromUser()
}
// fmt.Printf("%s", string(x))
c.JSON(200, gin.H{
"text": response,
})
})
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Test",
})
})
r.Run()
}