forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_identity.go
More file actions
33 lines (28 loc) · 875 Bytes
/
Copy pathnode_identity.go
File metadata and controls
33 lines (28 loc) · 875 Bytes
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
package common
import "os"
type NodeIdentity struct {
Name string `json:"name"`
Source string `json:"source"`
ManuallyConfigured bool `json:"manually_configured"`
ShouldConfigureManually bool `json:"should_configure_manually"`
}
func initNodeNameIdentity() {
if envNodeName := os.Getenv("NODE_NAME"); envNodeName != "" {
NodeName = envNodeName
NodeNameSource = NodeNameSourceManual
NodeNameManuallyConfigured = true
return
}
hostname, _ := os.Hostname()
NodeName = hostname
NodeNameSource = NodeNameSourceHostname
NodeNameManuallyConfigured = false
}
func GetNodeIdentity() NodeIdentity {
return NodeIdentity{
Name: NodeName,
Source: NodeNameSource,
ManuallyConfigured: NodeNameManuallyConfigured,
ShouldConfigureManually: !NodeNameManuallyConfigured,
}
}