2016-04-13 07:22:04 +00:00
|
|
|
package gorush
|
2016-03-25 01:23:46 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-03-25 02:40:29 +00:00
|
|
|
"runtime"
|
2017-01-19 09:08:12 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2016-03-25 01:23:46 +00:00
|
|
|
)
|
|
|
|
|
2016-05-09 06:48:07 +00:00
|
|
|
var version string
|
|
|
|
|
2016-06-25 13:40:38 +00:00
|
|
|
// SetVersion for setup version string.
|
2016-05-09 06:48:07 +00:00
|
|
|
func SetVersion(ver string) {
|
|
|
|
version = ver
|
|
|
|
}
|
|
|
|
|
2016-06-25 13:40:38 +00:00
|
|
|
// GetVersion for get current version.
|
2016-05-19 14:45:42 +00:00
|
|
|
func GetVersion() string {
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
2016-04-13 07:22:04 +00:00
|
|
|
// PrintGoRushVersion provide print server engine
|
|
|
|
func PrintGoRushVersion() {
|
|
|
|
fmt.Printf(`GoRush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`,
|
2016-05-09 06:48:07 +00:00
|
|
|
version,
|
2016-03-25 01:23:46 +00:00
|
|
|
runtime.Compiler,
|
|
|
|
runtime.Version())
|
2016-07-20 09:06:26 +00:00
|
|
|
fmt.Println()
|
2016-03-25 01:23:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 06:59:28 +00:00
|
|
|
// VersionMiddleware : add version on header.
|
2016-03-25 01:23:46 +00:00
|
|
|
func VersionMiddleware() gin.HandlerFunc {
|
|
|
|
// Set out header value for each response
|
|
|
|
return func(c *gin.Context) {
|
2017-02-21 06:15:14 +00:00
|
|
|
c.Header("X-DRONE-VERSION", version)
|
2016-03-25 01:23:46 +00:00
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|