gorush/router/version.go

52 lines
887 B
Go
Raw Permalink Normal View History

2021-07-13 18:16:09 +00:00
package router
import (
"fmt"
"runtime"
2017-01-19 09:08:12 +00:00
"github.com/gin-gonic/gin"
)
var (
version string
commit string
)
// SetVersion for setup version string.
func SetVersion(ver string) {
version = ver
}
// SetCommit for setup commit string.
func SetCommit(ver string) {
commit = ver
}
// GetVersion for get current version.
func GetVersion() string {
return version
}
// PrintGoRushVersion provide print server engine
func PrintGoRushVersion() {
if len(commit) > 7 {
commit = commit[:7]
}
fmt.Printf(`GoRush %s, Commit: %s, Compiler: %s %s, Copyright (C) 2023 Bo-Yi Wu, Inc.`,
version,
commit,
runtime.Compiler,
runtime.Version())
fmt.Println()
}
// VersionMiddleware : add version on header.
func VersionMiddleware() gin.HandlerFunc {
// Set out header value for each response
return func(c *gin.Context) {
2018-03-22 12:41:00 +00:00
c.Header("X-GORUSH-VERSION", version)
c.Next()
}
}