forked from provenance-io/cosmovisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.go
36 lines (29 loc) · 748 Bytes
/
json.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
package cosmovisor
import (
"encoding/json"
"strings"
)
// isJSONLog returns whether the string contains json, and if so, returns that json.
func isJSONLog(s string) (string, bool) {
beg := strings.Index(s, "{")
end := strings.LastIndex(s, "}")
if beg == end || beg > end {
return "", false
}
// Doesn't contain `...."message":"UPGRADE...NEEDED"....`
if !strings.Contains(s, "\"message\":\"UPGRADE") {
return "", false
}
return s[beg : end+1], true
}
type jsonLogMessage struct {
Err string `json:"err"`
Message string `json:"message"`
}
func parseJSONLog(s string) (jsonLogMessage, error) {
m := jsonLogMessage{}
if err := json.Unmarshal([]byte(s), &m); err != nil {
return jsonLogMessage{}, err
}
return m, nil
}