-
Notifications
You must be signed in to change notification settings - Fork 0
/
bilingual_root.go
77 lines (68 loc) · 1.91 KB
/
bilingual_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
77
package textra
import (
"encoding/json"
"fmt"
)
// List of bilingual entries.
const BILINGUALROOT = "bilingual_root"
type BilingualRootRequest struct {
LangS string `json:"lang_s"`
LangT string `json:"lang_t"`
Order string `json:"order"`
Limit string `json:"limit"`
Offset string `json:"offset"`
}
type BilingualRooListResult 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 []BilingualRootList `json:"list"`
} `json:"result"`
} `json:"resultset"`
}
type BilingualRootList struct {
ID int `json:"id"`
Name string `json:"name"`
SourceLanguage string `json:"source_language"`
TargetLanguage string `json:"target_language"`
Provide int `json:"provide"`
ProvideTarget string `json:"provide_target"`
}
func (tra *TexTra) BilingualRootGet(request *BilingualRootRequest) ([]BilingualRootList, error) {
values := tra.apiValues()
values.Add("api_name", BILINGUALROOT)
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.BilingualRootDecode(ret)
if err != nil {
return nil, err
}
return result.Resultset.Result.List, nil
}
func (tra *TexTra) BilingualRootDecode(ret []byte) (*BilingualRooListResult, error) {
result := new(BilingualRooListResult)
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
}