-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuq.go
64 lines (53 loc) · 1.12 KB
/
fuq.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
61
62
63
64
package fuq
import (
"fmt"
"os"
)
type Client struct {
Password string `json:"password"`
Client string `json:"client"`
}
type NodeInfo struct {
Node string `json:"node"`
Pid int `json:"pid"`
Session string `json:"session"`
UniqName string `json:"unique_name,omitempty"`
Tags []string `json:"tags,omitempty"`
NumProc int `json:"nproc"`
}
func (ni NodeInfo) Prefix() string {
return fmt.Sprintf("%s:%d", ni.Node, ni.Pid)
}
func NewNodeInfo(nproc int, tags ...string) (NodeInfo, error) {
hostname, err := os.Hostname()
if err != nil {
return NodeInfo{}, err
}
pid := os.Getpid()
return NodeInfo{
Node: hostname,
Pid: pid,
Tags: tags,
NumProc: nproc,
}, nil
}
/* HasTag returns whether the NodeInfo has a given tag. At the moment,
* this is a simple linear scan, which is probably enough for most
* intended purposes.
*/
func (ni NodeInfo) HasTag(tag string) bool {
for _, t := range ni.Tags {
if t == tag {
return true
}
}
return false
}
type Hello struct {
Auth string `json:"auth"`
NodeInfo
}
type Registration struct {
Name string
Cookie Cookie
}