-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (31 loc) · 725 Bytes
/
Copy pathmain.go
File metadata and controls
38 lines (31 loc) · 725 Bytes
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"
"github.com/gin-gonic/gin"
"net/http"
"os"
"time"
)
func main() {
r := gin.Default()
// Add V1 APIs
{
rgV1 := r.Group("/api/v1")
// Ping test
rgV1.GET("/ping", func(c *gin.Context) {
c.String(http.StatusOK, "pong")
})
// Get current datetime
rgV1.POST("/datetime", func(c *gin.Context) {
// Format: "Mon, 02 Jan 2006 15:04:05 -0700"
c.JSONP(http.StatusOK, map[string]string{"dt": time.Now().Format(time.RFC1123Z)})
})
}
// Listen and Server in 0.0.0.0:12345
err := r.Run(":12345")
if err != nil {
fmt.Println("Failed to run the server", err)
// We need to fail with exit code - systemd service will reboot on failure, if configured.
os.Exit(1)
}
}