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
|
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
r := gin.Default()
r.GET("/hello", helloHandler)
r.GET("/world", worldHandler)
r.Run()
}
func helloHandler(c *gin.Context) {
resp, err := helloService.Hello()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
"data": nil,
})
return
}
c.JSON(http.StatusInternalServerError, gin.H{
"message": "ok",
"data": resp,
})
}
func worldHandler(c *gin.Context) {
resp, err := worldService.World()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"message": err.Error(),
"data": nil,
})
return
}
c.JSON(http.StatusInternalServerError, gin.H{
"message": "ok",
"data": resp,
})
}
|