-
Notifications
You must be signed in to change notification settings - Fork 6
/
languages.go
40 lines (33 loc) · 1.25 KB
/
languages.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
package deepl
import (
"context"
"github.com/michimani/deepl-sdk-go/params"
"github.com/michimani/deepl-sdk-go/types"
)
// Languages calls the languages API with type "target" of the Deepl API.
func (c *Client) TargetLanguages(ctx context.Context) (*types.TargetLanguagesResponse, *types.ErrorResponse, error) {
params := ¶ms.LanguagesParams{LangType: types.LangTypeTarget}
res := types.TargetLanguagesResponse{}
errRes, err := languages(ctx, c, params, &res)
return &res, errRes, err
}
// Languages calls the languages API with type "source" of the Deepl API.
func (c *Client) SourceLanguages(ctx context.Context) (*types.SourceLanguagesResponse, *types.ErrorResponse, error) {
params := ¶ms.LanguagesParams{LangType: types.LangTypeSource}
res := types.SourceLanguagesResponse{}
errRes, err := languages(ctx, c, params, &res)
return &res, errRes, err
}
func languages(ctx context.Context, c *Client, params *params.LanguagesParams, res interface{}) (*types.ErrorResponse, error) {
endpoint := c.EndpointBase + types.EndpointLanguages
params.SetAuthnKey(c.AuthenticationKey)
requester := NewRequester(endpoint, params)
errRes, err := requester.Exec(res)
if err != nil {
return nil, err
}
if errRes != nil {
return errRes, nil
}
return nil, nil
}