Skip to content

Commit

Permalink
增加 uptime 查看
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyiwy committed Dec 2, 2019
1 parent 2525be4 commit 4d6cc32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/contoller/controler.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package contoller

import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"oktools/src/model"
"time"
)

var begin = time.Now()

func Uptime(c *gin.Context) {
now := time.Now()
c.String(http.StatusOK,
fmt.Sprintf("The system launched in %s. already running for %d days, %d hours, %d minues, %d seconds.",
begin.Format("2006-01-02 15:04:05"),
now.Day()-begin.Day(),
now.Hour()-begin.Hour(),
now.Minute()-begin.Minute(),
now.Second()-begin.Second()),
)
}

func Ping(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"msg": "pong"})
}
Expand Down
1 change: 1 addition & 0 deletions src/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func initRouter() *gin.Engine {

r.GET("/", contoller.Index)
r.GET("/ping", contoller.Ping)
r.GET("/uptime", contoller.Uptime)
r.GET("/ph/:size", service.PlaceHolder)

r.GET("/base64", contoller.Base64, middleware.UsageCount)
Expand Down

0 comments on commit 4d6cc32

Please sign in to comment.