-
Notifications
You must be signed in to change notification settings - Fork 0
/
environmentinfo.go
60 lines (49 loc) · 1.35 KB
/
environmentinfo.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
57
58
59
60
package buildinfo
import (
"fmt"
"time"
)
const (
// default value for EnvironmentInfo.User
DefaultUser = "unknown"
// default value for EnvironmentInfo.Host
DefaultHost = "localhost"
)
const (
userConcat = "@"
)
// EnvironmentInfo contains data about the build context of a project
type EnvironmentInfo struct {
User string `json:"user,omitempty"`
Host string `json:"host,omitempty"`
Date time.Time `json:"date,omitempty"`
}
// NewEnvironmentInfo returns a EnvironmentInfo instance with default values
func NewEnvironmentInfo() *EnvironmentInfo {
return &EnvironmentInfo{
User: DefaultUser,
Host: DefaultHost,
Date: time.Now(),
}
}
// String returns build user, -host, and -date information.
func (i *EnvironmentInfo) String() string {
return fmt.Sprintf("(user=%s, host=%s, date=%s)", i.User, i.Host, i.Date)
}
// Clone creates an independant copy of itself.
func (i *EnvironmentInfo) Clone() *EnvironmentInfo {
i2 := *i
return &i2
}
// Equal compares the fields of this instance to the given one
func (i *EnvironmentInfo) Equal(o *EnvironmentInfo) bool {
if i == nil || o == nil {
return i == nil && o == nil
}
return i.User == o.User && i.Host == o.Host && i.Date == o.Date
}
// UserHost returns the User and Host value
// concatenated by an @ character
func (i *EnvironmentInfo) UserHost() string {
return i.User + userConcat + i.Host
}