/
version.go
51 lines (42 loc) · 887 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package router
import (
"fmt"
"runtime"
"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) {
c.Header("X-GORUSH-VERSION", version)
c.Next()
}
}