-
Notifications
You must be signed in to change notification settings - Fork 701
/
runtime.go
56 lines (46 loc) · 894 Bytes
/
runtime.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
52
53
54
55
56
package application
import (
"os"
"time"
"github.com/douyu/jupiter/pkg/flag"
)
var (
appHost = os.Getenv("JUPITER_APP_HOST")
hostname string
)
func init() {
hn, err := os.Hostname()
if err != nil {
panic(err)
}
hostname = hn
}
// 通用状态信息
type RuntimeStats struct {
IP string `json:"ip"`
Hostname string `json:"hostname"`
Time string `json:"time"` // 每次展示数据的时间
Err string `json:"err"`
}
func NewRuntimeStats() RuntimeStats {
return RuntimeStats{
IP: EnvServerHost(),
Hostname: Hostname(),
Time: time.Now().Format("2006-01-02 15:04:05"),
}
}
// Hostname gets hostname.
func Hostname() string {
return hostname
}
// EnvServerHost gets JUPITER_APP_HOST.
func EnvServerHost() string {
host := flag.String("host")
if host != "" {
return host
}
if appHost == "" {
return "127.0.0.1"
}
return appHost
}