-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
executable file
·81 lines (71 loc) · 1.95 KB
/
util.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package golink
import (
"code.google.com/p/go-etree"
"fmt"
"strconv"
"strings"
"time"
)
func parseEveTs(in string) (time.Time, error) {
return time.Parse("2006-01-02 15:04:05", in)
}
func first(s string, _ bool) string {
return s
}
func getStrValue(e etree.Element, child string) (string, error) {
c := e.Find(child)
if c == nil {
return "", fmt.Errorf("Unable to find child element %v of element %v", child, e.Tag())
}
return c.Text(), nil
}
func getTimeValue(e etree.Element, child string) (time.Time, error) {
c := e.Find(child)
if c == nil {
return time.Time{}, fmt.Errorf("Unable to find child element %v of element %v", child, e.Tag())
}
return parseEveTs(c.Text())
}
func getIntValue(e etree.Element, child string) (int64, error) {
c := e.Find(child)
if c == nil {
return 0, fmt.Errorf("Unable to find child element %v of element %v", child, e.Tag())
}
return strconv.ParseInt(c.Text(), 0, 64)
}
func getFloatValue(e etree.Element, child string) (float64, error) {
c := e.Find(child)
if c == nil {
return 0, fmt.Errorf("Unable to find child element %v of element %v", child, e.Tag())
}
return strconv.ParseFloat(c.Text(), 64)
}
func getBoolValue(e etree.Element, child string) (bool, error) {
c := e.Find(child)
if c == nil {
return false, fmt.Errorf("Unable to find child element %v of element %v", child, e.Tag())
}
if c.Text() == "True" {
return true, nil
} else if c.Text() == "False" {
return false, nil
}
return false, fmt.Errorf("Unknown bool literal value: %v", c.Text())
}
func extractKeyval(data string) map[string]string {
pairs := strings.FieldsFunc(data, func(r rune) bool { return r == '\n' })
ret := make(map[string]string)
for _, s := range pairs {
r := strings.Split(s, ": ")
ret[r[0]] = r[1]
}
return ret
}
func parseMSDate(data string) (time.Time, error) {
i, err := strconv.ParseInt(data, 0, 64)
if err != nil {
return time.Time{}, err
}
i = (i / 10000000) - 11644473600
return time.Unix(i, 0), nil
}