-
Notifications
You must be signed in to change notification settings - Fork 0
/
glossaries_root.go
76 lines (67 loc) · 1.8 KB
/
glossaries_root.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
package textra
import (
"encoding/json"
"fmt"
)
// List of glossaries entries.
const TERMROOT = "term_root"
type TermRootRequest struct {
LangS string `json:"lang_s"`
LangT string `json:"lang_t"`
Order string `json:"order"`
Limit string `json:"limit"`
Offset string `json:"offset"`
}
type TermRootSetResult struct {
Resultset struct {
Code int `json:"code"`
Message string `json:"message"`
Total int `json:"total"`
Request struct {
URL string `json:"url"`
Limit int `json:"limit"`
Offset int `json:"offset"`
} `json:"request"`
Result struct {
List []TermRootList `json:"list"`
} `json:"result"`
} `json:"resultset"`
}
type TermRootList struct {
ID int `json:"id"`
Name string `json:"name"`
SourceLanguage string `json:"source_language"`
TargetLanguage string `json:"target_language"`
Provide int `json:"provide"`
}
func (tra *TexTra) TermRootGet(request *TermRootRequest) ([]TermRootList, error) {
values := tra.apiValues()
values.Add("api_name", TERMROOT)
values.Add("api_param", "get")
if request != nil {
values.Add("lang_s", request.LangS)
values.Add("lang_t", request.LangT)
values.Add("order", request.Order)
values.Add("limit", request.Limit)
values.Add("offset", request.Offset)
}
ret, err := tra.apiPost(values)
if err != nil {
return nil, err
}
result, err := tra.TermRootDecode(ret)
if err != nil {
return nil, err
}
return result.Resultset.Result.List, nil
}
func (tra *TexTra) TermRootDecode(ret []byte) (*TermRootSetResult, error) {
result := new(TermRootSetResult)
if err := json.Unmarshal(ret, result); err != nil {
return nil, err
}
if result.Resultset.Code != 0 {
return result, fmt.Errorf("%d: %s", result.Resultset.Code, errorText[result.Resultset.Code])
}
return result, nil
}