-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhandler.go
78 lines (66 loc) · 1.38 KB
/
handler.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"net"
"net/http"
"github.com/gin-gonic/gin"
)
func readTodoHandler(c *gin.Context) {
todos, err := database.GetAllTodos()
if err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{
"errors": err.Error(),
})
return
}
fmt.Println(todos)
c.JSON(http.StatusOK, todos)
}
func insertTodoHandler(c *gin.Context) {
if err := database.SaveTodo(c.Param("value")); err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{
"errors": err.Error(),
})
return
}
readTodoHandler(c)
}
func deleteTodoHandler(c *gin.Context) {
if err := database.DeleteTodo(c.Param("value")); err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{
"errors": err.Error(),
})
return
}
readTodoHandler(c)
}
func healthCheckHandler(c *gin.Context) {
c.JSON(http.StatusOK, database.GetHealthStatus())
}
func whoAmIHandler(c *gin.Context) {
ifaces, err := net.Interfaces()
if err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{
"errors": err.Error(),
})
return
}
addresses, err := getAllAddresses(ifaces)
if err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{
"errors": err.Error(),
})
return
}
c.JSON(http.StatusOK, addresses)
}
func versionHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"version": appVersion,
})
}