-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
63 lines (53 loc) · 843 Bytes
/
utils.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
package main
import (
"strconv"
"syscall"
)
func checkerror(err error) {
if err != nil {
panic(err)
}
}
func checkok(ok bool) {
if !ok {
panic("")
}
}
type SyscallWriteCloser struct {
fd int
}
func (p *SyscallWriteCloser) Write(data []byte) (int, error) {
return syscall.Write(p.fd, data)
}
func (p *SyscallWriteCloser) Close() error {
return syscall.Close(p.fd)
}
func ExtractIntValue(idValue interface{}) int {
switch value := idValue.(type) {
case float64:
return int(value)
case string:
r, err := strconv.Atoi(value)
checkerror(err)
return r
case int:
return value
default:
panic(value)
}
}
func str2int(id string) int {
switch id {
case "yaml":
return YamlID
case "json":
return JSONID
case "xml":
return XMLID
case "ruff":
return RUFFID
case "rome":
return ROMEID
}
panic(id)
}