forked from schweikert/fping-exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtargetmap.go
More file actions
37 lines (30 loc) · 729 Bytes
/
targetmap.go
File metadata and controls
37 lines (30 loc) · 729 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
34
35
36
37
package main
import (
"sync"
)
// WorkerSpec and TargetSpec are given by the client and represent respectively
// fping parameters that are common across a group of targets, and the targets
// (hosts to ping). (for WorkerSpec -> see worker.go)
type TargetSpec struct {
host string
}
// TargetMap maps a WorkerSpec+TargetSpec to a Worker and Target
type TargetMap struct {
sync.Mutex
workers map[WorkerSpec]*Worker
}
var tm TargetMap = TargetMap{
workers: make(map[WorkerSpec]*Worker),
}
func GetTarget(ws WorkerSpec, ts TargetSpec) *Target {
// retrieve Worker
tm.Lock()
w, ok := tm.workers[ws]
if !ok {
w = NewWorker(ws)
tm.workers[ws] = w
}
tm.Unlock()
// retrieve Target
return w.GetWorkerTarget(ts)
}