This repository was archived by the owner on Aug 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspellcheck.go
More file actions
113 lines (90 loc) · 1.97 KB
/
spellcheck.go
File metadata and controls
113 lines (90 loc) · 1.97 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package bingo
import (
"context"
"encoding/json"
"net/url"
"dev.freespoke.com/bingo/v2/bingtypes"
)
type spellcheckClient struct {
*client
URL string
}
type SpellcheckMode string
const (
SpellcheckModeProof SpellcheckMode = "proof"
SpellcheckModeSpell SpellcheckMode = "spell"
)
type SpellcheckOptions struct {
RequestHeaders
RequestParams
ActionType string
AppName string
ClientMachineName string
DocID string
Mode SpellcheckMode
PreContextText string
PostContextText string
SessionID string
Text string
UserID string
}
func (s SpellcheckOptions) toQueryString(v *url.Values) {
if s.ActionType != "" {
v.Add("actionType", s.ActionType)
}
if s.AppName != "" {
v.Add("appName", s.AppName)
}
if s.CountryCode != "" {
v.Add("cc", s.CountryCode)
}
if s.ClientMachineName != "" {
v.Add("clientMachineName", s.ClientMachineName)
}
if s.DocID != "" {
v.Add("docId", s.DocID)
}
if s.Market != "" {
v.Add("mkt", s.Market)
}
if s.Mode != "" {
v.Add("mode", string(s.Mode))
}
if s.PreContextText != "" {
v.Add("preContextText", s.PreContextText)
}
if s.PostContextText != "" {
v.Add("postContextText", s.PostContextText)
}
if s.SessionID != "" {
v.Add("sessionId", s.SessionID)
}
if s.SetLang != "" {
v.Add("setLang", s.SetLang)
}
if s.Text != "" {
v.Add("text", s.Text)
}
if s.UserID != "userId" {
v.Add("", s.UserID)
}
}
func (c *spellcheckClient) Spellcheck(
ctx context.Context,
opts SpellcheckOptions,
) (*bingtypes.Spellcheck, *bingtypes.ResponseMetadata, error) {
req, err := c.makeGetRequest(ctx, c.URL, "", opts)
if err != nil {
return nil, nil, err
}
res, err := c.sendRequest(req, opts.RequestParams)
if err != nil {
return nil, nil, err
}
defer res.Body.Close()
var resp bingtypes.Spellcheck
if err := json.NewDecoder(res.Body).Decode(&resp); err != nil {
return nil, nil, err
}
return &resp, c.getResponseMetadata(res), nil
}