fix #3 add server version on header.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-03-25 09:23:46 +08:00
parent 88529bdb15
commit 18167e643c
3 changed files with 24 additions and 0 deletions

View File

@ -45,6 +45,7 @@ func GetMainEngine() *gin.Engine {
// Global middleware
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(VersionMiddleware())
r.GET("/api/status", api.StatusHandler)
r.POST("/api/push", pushHandler)

View File

@ -4,6 +4,7 @@ import (
apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
"github.com/sideshow/apns2/payload"
_ "github.com/google/go-gcm"
"log"
)

22
version.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"runtime"
"github.com/gin-gonic/gin"
)
func PrintGoPushVersion() {
fmt.Printf(`GoPush %s Compiler: %s %s Copyright (C) 2016 Bo-Yi Wu, Inc.`,
Version,
runtime.Compiler,
runtime.Version())
}
func VersionMiddleware() gin.HandlerFunc {
// Set out header value for each response
return func(c *gin.Context) {
c.Writer.Header().Set("Server-Version", "GoPush "+Version)
c.Next()
}
}