-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (31 loc) · 795 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
package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
func generatePreorderRelation(set []int) map[string]bool {
preorderRelation := make(map[string]bool)
for _, element := range set {
preorderRelation[fmt.Sprintf("[%d,%d]", element, element)] = true
for _, otherElement := range set {
if element <= otherElement {
preorderRelation[fmt.Sprintf("[%d,%d]", element, otherElement)] = true
}
}
}
return preorderRelation
}
func main() {
r := gin.Default()
r.POST("/preorder", func(c *gin.Context) {
var set []int
if err := c.BindJSON(&set); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
return
}
preorderRelation := generatePreorderRelation(set)
c.JSON(http.StatusOK, preorderRelation)
})
r.Run()
}