forked from ycrash/yc-360-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm3.go
More file actions
37 lines (34 loc) · 618 Bytes
/
m3.go
File metadata and controls
37 lines (34 loc) · 618 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 shell
import (
"encoding/json"
"strconv"
"strings"
)
type M3Resp struct {
Actions []string
Tags []string
Timestamp string
}
func ParseJsonResp(resp []byte) (pids []int, tags []string, timestamp string, err error) {
r := &M3Resp{}
err = json.Unmarshal(resp, r)
if err != nil {
return
}
tags = r.Tags
timestamp = r.Timestamp
for _, s := range r.Actions {
if strings.HasPrefix(s, "capture ") {
ss := strings.Split(s, " ")
if len(ss) == 2 {
id := ss[1]
pid, err := strconv.Atoi(id)
if err != nil {
continue
}
pids = append(pids, pid)
}
}
}
return
}