-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.go
More file actions
172 lines (153 loc) · 4.8 KB
/
Copy pathmisc.go
File metadata and controls
172 lines (153 loc) · 4.8 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package discard
import (
"io"
"log"
"os"
)
func (c *Client) Compress(t, text, url string) (interface{}, error) {
params := map[string]interface{}{"type": t}
if t == "text" && text != "" {
params["text"] = text
}
if t == "url" && url != "" {
params["url"] = url
}
return c.makeRequest("GET", "/api/compress", params, nil)
}
func (c *Client) Decompress(t, data, url string) (interface{}, error) {
params := map[string]interface{}{"type": t}
if t == "text" && data != "" {
params["data"] = data
}
if t == "url" && url != "" {
params["url"] = url
}
return c.makeRequest("GET", "/api/decompress", params, nil)
}
func (c *Client) MathQuiz(difficulty, steps, allowNegative, numQuestions string) (interface{}, error) {
params := map[string]interface{}{}
if difficulty != "" {
params["difficulty"] = difficulty
}
if steps != "" {
params["steps"] = steps
}
if allowNegative != "" {
params["allow_negative"] = allowNegative
}
if numQuestions != "" {
params["num_questions"] = numQuestions
}
return c.makeRequest("GET", "/api/tools/math", params, nil)
}
func (c *Client) MorseText(text, mode string) (interface{}, error) {
params := map[string]interface{}{"text": text, "mode": mode}
return c.makeRequest("GET", "/api/tools/morse", params, nil)
}
func (c *Client) ReadQR(imagePath string) (interface{}, error) {
file, err := os.Open(imagePath)
if err != nil {
return nil, err
}
defer func() {
if cerr := file.Close(); cerr != nil {
log.Printf("discard: failed to close file in ReadQR: %v", cerr)
}
}()
files := map[string]io.Reader{"image": file}
return c.MakeFormDataRequest("/api/tools/readqr", nil, files)
}
func (c *Client) TextToSpeech(text, lang string) (interface{}, error) {
params := map[string]interface{}{"text": text}
if lang != "" {
params["lang"] = lang
}
return c.makeRequest("GET", "/api/tools/tts", params, nil)
}
func (c *Client) WebsiteSEO(url string) (interface{}, error) {
params := map[string]interface{}{"url": url}
return c.makeRequest("GET", "/api/tools/seo", params, nil)
}
func (c *Client) StandardPing(url, lang string) (interface{}, error) {
params := map[string]interface{}{"url": url}
if lang != "" {
params["lang"] = lang
}
return c.makeRequest("GET", "/api/tools/ping", params, nil)
}
func (c *Client) ToASCII(imagePath string) (interface{}, error) {
file, err := os.Open(imagePath)
if err != nil {
return nil, err
}
defer func() {
if cerr := file.Close(); cerr != nil {
log.Printf("discard: failed to close file in ToASCII: %v", cerr)
}
}()
files := map[string]io.Reader{"file": file}
return c.MakeFormDataRequest("/api/tools/ascii", nil, files)
}
func (c *Client) RandomUUID() (interface{}, error) {
return c.makeRequest("GET", "/api/tools/uuid", nil, nil)
}
func (c *Client) GenerateHash(data, algo string) (interface{}, error) {
params := map[string]interface{}{"data": data, "algo": algo}
return c.makeRequest("GET", "/api/tools/hash", params, nil)
}
func (c *Client) StrongPassword() (interface{}, error) {
return c.makeRequest("GET", "/api/tools/password", nil, nil)
}
func (c *Client) CompressFile(filePath, t string) (interface{}, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer func() {
if cerr := file.Close(); cerr != nil {
log.Printf("discard: failed to close file in CompressFile: %v", cerr)
}
}()
params := map[string]interface{}{"type": t}
files := map[string]io.Reader{"file": file}
return c.MakeFormDataRequest("/api/compress", params, files)
}
func (c *Client) DecompressFile(filePath, t string) (interface{}, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer func() {
if cerr := file.Close(); cerr != nil {
log.Printf("discard: failed to close file in DecompressFile: %v", cerr)
}
}()
params := map[string]interface{}{"type": t}
files := map[string]io.Reader{"file": file}
return c.MakeFormDataRequest("/api/decompress", params, files)
}
func (c *Client) MarkdownToHTML(markdown string) (interface{}, error) {
body := map[string]interface{}{"markdown": markdown}
return c.makeRequest("POST", "/api/tools/markdown", nil, body)
}
func (c *Client) ExifReader(imagePath string) (interface{}, error) {
file, err := os.Open(imagePath)
if err != nil {
return nil, err
}
defer func() {
if cerr := file.Close(); cerr != nil {
log.Printf("discard: failed to close file in ExifReader: %v", cerr)
}
}()
files := map[string]io.Reader{"image": file}
return c.MakeFormDataRequest("/api/tools/exif", nil, files)
}
func (c *Client) MinifyCSS(css string) (interface{}, error) {
body := map[string]interface{}{"css": css}
return c.makeRequest("POST", "/api/tools/minifycss", nil, body)
}
func (c *Client) JsonBeautify(jsonStr string) (interface{}, error) {
body := map[string]interface{}{"json": jsonStr}
return c.makeRequest("POST", "/api/json/format", nil, body)
}