From 18167e643c0573b7841615e0427fcf579961767f Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 25 Mar 2016 09:23:46 +0800 Subject: [PATCH] fix #3 add server version on header. Signed-off-by: Bo-Yi Wu --- main.go | 1 + notification.go | 1 + version.go | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 version.go diff --git a/main.go b/main.go index d49d757..e01a0d4 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/notification.go b/notification.go index 4ce7744..8d579ee 100644 --- a/notification.go +++ b/notification.go @@ -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" ) diff --git a/version.go b/version.go new file mode 100644 index 0000000..cfb2a59 --- /dev/null +++ b/version.go @@ -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() + } +}