-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
70 lines (58 loc) · 1.36 KB
/
types.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
package triparclient
import (
"encoding/json"
)
type Status struct {
Atime float64 `json:"atime"`
Blksize int64 `json:"blksize"`
Blocks int64 `json:"blocks"`
Ctime float64 `json:"ctime"`
Dev int32 `json:"dev"`
Gid int32 `json:"gid"`
// Ino int64 `json:"ino"`
Mode int32 `json:"mode"`
Mtime float64 `json:"mtime"`
Nlink int32 `json:"nlink"`
Rdev int32 `json:"rdev"`
Size int64 `json:"size"`
Uid int32 `json:"uid"`
}
type Stat struct {
Path string `json:"path"`
Status Status `json:"status"`
}
func (s Stat) IsDir() bool {
return (((s.Status.Mode) & (0170000)) == (0040000))
}
type Entries struct {
Entries []Entry `json:"entries"`
}
type Entry struct {
Name string `json:"name"`
}
type Error struct {
Code int `json:"error_code"`
LMsg string `json:"long_message"`
SMsg string `json:"short_message"`
}
func (e *Error) Error() string {
return e.SMsg
}
func UnmarshalError(data []byte) (*Error, error) {
required := struct {
Code *int `json:"error_code"`
LMsg *string `json:"long_message"`
SMsg *string `json:"short_message"`
}{}
if err := json.Unmarshal(data, &required); err != nil {
return nil, err
}
if required.Code == nil || required.LMsg == nil || required.SMsg == nil {
return nil, nil
}
return &Error{
Code: *required.Code,
LMsg: *required.LMsg,
SMsg: *required.SMsg,
}, nil
}