-
Notifications
You must be signed in to change notification settings - Fork 0
/
apyhub.go
400 lines (293 loc) · 10 KB
/
apyhub.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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package apyhub
import (
"github.com/apyhub/apyhub.go/convert"
"github.com/apyhub/apyhub.go/data"
"github.com/apyhub/apyhub.go/extract"
"github.com/apyhub/apyhub.go/generate"
h "github.com/apyhub/apyhub.go/helper"
"github.com/apyhub/apyhub.go/imageprocessor"
"github.com/apyhub/apyhub.go/search"
"github.com/apyhub/apyhub.go/validation"
)
// Set the token
func InitApyHub(auth interface{}) error {
switch auth := auth.(type) {
case string:
h.Token = auth
case h.BasicAuth:
h.Auth = h.BasicAuth(auth)
default:
return h.ErrTypeNotMatch
}
return nil
}
/*
##Functions
### csvToExcel
Converts a CSV file or URL to an Excel file.
**`Example 1 : convert csv file to Excel file`**
```go
import (
apyhub "github.com/apyhub/apyhub.go"
)
File,err :=os.Open("any csv file")
if err!=nil {
log.Fatal(err)
}
// Input is a file
byt,err :=apyhub.CsvToExcelAsFile(File)
```
**`Example 2 : convert csv file url to Excel file`**
```go
fileUrl :="csv file url"
// Input is a url
byt,err :=apyhub.CsvToExcelAsFile(fileUrl)
```
#### Defined in
[convert/csvToExcel.go:63](https://github.com/apyhub/apyhub.go/blob/main/convert/csvToExcel.go#L63)
*/
func CsvToExcelAsFile(urlorFile interface{}) ([]byte, error) {
return convert.CsvToExcelAsFile(urlorFile)
}
/*
**`Example 3 : convert csv file to AWS presigned url`**
```go
// Input is a file
File,err :=os.Open("any csv file")
if err!=nil {
log.Fatal(err)
}
url,err :=apyhub.CsvToExcelAsUrl(File)
```
**`Example 4 : convert csv file url to AWS presigned url`**
```go
fileUrl :="csv file url"
// Input is a url
url,err :=apyhub.CsvToExcelAsUrl(fileUrl)
```
#### Defined in
[convert/csvToExcel.go:38](https://github.com/apyhub/apyhub.go/blob/main/convert/csvToExcel.go#L38)
**`Link`**
https://apyhub.com/utility/converter-csv-excel
#### Parameters
<table>
<tr><th>Name</th><th>Type</th><th>Description</th></tr>
<tr><td>input</td><td> <code>"string"</code> | <code>Buffer</code></td><td>The html file or URL.</td></tr>
<tr><td>output</td><td><code>[]byte</code> | <code>"string"</code> </td><td>The format for the response.</td></tr>
</table>
#### Returns
The data for the output file as slice of byte or Url as a string.
*/
func CsvToExcelAsUrl(urlorFile interface{}) (string, error) {
return convert.CsvToExcelAsURL(urlorFile)
}
func HtmlToPdfAsFile(urlorFile interface{}, landscape bool) ([]byte, error) {
return convert.HtmlToPdfAsFile(urlorFile, landscape)
}
func HtmlToPdfAsUrl(urlorFile interface{}, landscape bool) (string, error) {
return convert.HtmlToPdfAsUrl(urlorFile, landscape)
}
/*
### imageToPdf
Converts a image file or URL to an pdf file.
**`Example 1 : convert image to pdf file`**
```go
import (
apyhub "github.com/apyhub/apyhub.go"
)
// Input is a file
File,err :=os.Open("any image")
if err!=nil {
log.Fatal(err)
}
byt,err :=apyhub.ImageToPdfAsFile(File)
```
**`Example 2 : convert image url to pdf file`**
```go
// Input is a url
fileUrl :="image url"
byt,err :=apyhub.ImageToPdfAsFile(fileUrl)
```
#### Defined in
[convert/imageToPdf.go:12](https://github.com/apyhub/apyhub.go/blob/main/convert/imageToPdf.go#L12)
*/
func ImageToPdfAsFile(urlorFile interface{}, landscape bool) ([]byte, error) {
return convert.ImageToPdfAsFile(urlorFile, landscape)
}
func ImageToPdfAsUrl(urlorFile interface{}, landscape bool) (string, error) {
return convert.ImageToPdfAsUrl(urlorFile, landscape)
}
func MarkdownToHtmlAsFile(urlorFile interface{}) ([]byte, error) {
return convert.MarkdownToHtmlAsFile(urlorFile)
}
func MarkdownToHtmlAsUrl(urlorFile interface{}) (string, error) {
return convert.MarkdownToHtmlAsUrl(urlorFile)
}
func PresentationToPdfAsFile(urlorFile interface{}, landscape bool) ([]byte, error) {
return convert.PresentationToPdfAsFile(urlorFile, landscape)
}
func PresentationToPdfAsUrl(urlorFile interface{}, landscape bool) (string, error) {
return convert.PresentationToPdfAsUrl(urlorFile, landscape)
}
func SpreadsheetToPdfAsFile(urlorFile interface{}, landscape bool) ([]byte, error) {
return convert.SpreadsheetToPdfAsFile(urlorFile, landscape)
}
func SpreadsheetToPdfAsUrl(urlorFile interface{}, landscape bool) (string, error) {
return convert.SpreadsheetToPdfAsUrl(urlorFile, landscape)
}
func WordToPdfAsFile(urlorFile interface{}, landscape bool) ([]byte, error) {
return convert.WordToPdfAsFile(urlorFile, landscape)
}
func WordToPdfAsUrl(urlorFile interface{}, landscape bool) (string, error) {
return convert.WordToPdfAsUrl(urlorFile, landscape)
}
// Validation
func VatValidation(vat string) (bool, error) {
return validation.VatValidation(vat)
}
// IN and UK postcode
func PostCodeValidation(postcode string, checkType validation.CheckType) (bool, error) {
return validation.PostCodeValidation(postcode, checkType)
}
// Email DNS and Acadamic
func EmailValidation(email string, checkType validation.CheckType) (bool, error) {
return validation.EmailValidation(email, checkType)
}
// Extraction
func TextFromWebpage(url string) (string, error) {
return extract.TextFromWebpage(url)
}
func TextFromWord(urlorFile interface{}) (string, error) {
return extract.TextFromWord(urlorFile)
}
func TextFromPdf(urlorFile interface{}) (string, error) {
return extract.TextFromPdf(urlorFile)
}
func ImageMetadata(urlorFile interface{}) (map[string]interface{}, error) {
return extract.ImageMetadata(urlorFile)
}
func FuzzySearch(source string, target string, unicodeNormalize bool) ([]string, error) {
return search.FuzzySearch(source, target, unicodeNormalize)
}
// unarchiver
func UnArchiveAsURL(conv interface{}) ([]string, error) {
return extract.UnArchiveAsURL(conv)
}
func SecureUnArchiveAsURL(password string, conv interface{}) ([]string, error) {
return extract.SecureUnArchiveAsURL(password, conv)
}
// Data getting Information
func Country(countrycode string) (h.Country, error) {
return data.Country(countrycode)
}
func CountryList() ([]h.Country, error) {
return data.CountryList()
}
func CurrencyConv(currency h.CurrencyConverter) (float64, error) {
return data.CurrencyConv(currency)
}
func CurrencyList() ([]h.Currency, error) {
return data.CurrencyList()
}
func Timezones() ([]h.Timezone, error) {
return data.Timezones()
}
// Generate Charts, bar code,qr code and pdf
func BarChartAsFile(charts h.Chart) ([]byte, error) {
return generate.BarChartAsFile(charts)
}
func BarChartAsURL(charts h.Chart) (string, error) {
return generate.BarChartAsURL(charts)
}
func PieChartAsFile(charts h.Chart) ([]byte, error) {
return generate.PieChartAsFile(charts)
}
func PieChartAsURL(charts h.Chart) (string, error) {
return generate.PieChartAsURL(charts)
}
func StackedBarChartAsFile(charts h.StackedBarChart) ([]byte, error) {
return generate.StackedBarChartAsFile(charts)
}
func StackedBarChartAsURL(charts h.StackedBarChart) (string, error) {
return generate.StackedBarChartAsURL(charts)
}
func BarcodeAsFile(content string) ([]byte, error) {
return generate.BarcodeAsFile(content)
}
func BarcodeAsURL(content string) (string, error) {
return generate.BarcodeAsURL(content)
}
func QrcodeAsFile(content string) ([]byte, error) {
return generate.QrcodeAsFile(content)
}
func QrcodeAsURL(content string) (string, error) {
return generate.QrcodeAsURL(content)
}
func HtmlContentToPdfFile(content string) ([]byte, error) {
return generate.HtmlContentToPdfFile(content)
}
func HtmlContentToPdfURL(content string) (string, error) {
return generate.HtmlContentToPdfAsUrl(content)
}
func WebpageToPdfFile(url string, margin float64) ([]byte, error) {
return generate.WebpageToPdfFile(url, margin)
}
func WebpageToPdfURL(url string, margin float64) (string, error) {
return generate.WebpageToPdfURL(url, margin)
}
func ScreenshotWebpageAsFile(url string, quality int, delay int) ([]byte, error) {
return generate.ScreenshotWebpageAsFile(url, quality, delay)
}
func ScreenshotWebpageAsURL(url string, quality int, delay int) (string, error) {
return generate.ScreenshotWebpageAsURL(url, quality, delay)
}
func IcalGeneratorAsFile(calendar h.CalenderEvent) ([]byte, error) {
return generate.IcalGeneratorAsFile(calendar)
}
func IcalGeneratorAsURL(calendar h.CalenderEvent) (string, error) {
return generate.IcalGeneratorAsURL(calendar)
}
// Archiver and secure archiver
func ArchiveAsFile(conv ...interface{}) ([]byte, error) {
return generate.ArchiveAsFile(conv)
}
func ArchiveAsURL(conv ...interface{}) (string, error) {
return generate.ArchiveAsURL(conv)
}
func SecureArchiveFile(password string, conv ...interface{}) ([]byte, error) {
return generate.SecureArchiveFile(password, conv)
}
func SecureArchiveAsURL(password string, conv ...interface{}) (string, error) {
return generate.SecureArchiveAsURL(password, conv)
}
// image processing
func CompressImageAsFile(conv interface{}, quality int) ([]byte, error) {
return imageprocessor.CompressImageAsFile(conv, quality)
}
func CompressImageAsURL(conv interface{}, quality int) (string, error) {
return imageprocessor.CompressImageAsURL(conv, quality)
}
func CropImageAsFile(conv interface{}, width int, height int) ([]byte, error) {
return imageprocessor.CropImageAsFile(conv, width, height)
}
func CropImageAsURL(conv interface{}, width int, height int) (string, error) {
return imageprocessor.CropImageAsURL(conv, width, height)
}
func ResizeImageAsFile(conv interface{}, width int, height int) ([]byte, error) {
return imageprocessor.ResizeImageAsFile(conv, width, height)
}
func ResizeImageAsURL(conv interface{}, width int, height int) (string, error) {
return imageprocessor.ResizeImageAsURL(conv, width, height)
}
func WatermarkImageAsFile(conv h.Watermark, width int, height int) ([]byte, error) {
return imageprocessor.WatermarkImageAsFile(conv, width, height)
}
func WatermarkImageAsURL(conv h.Watermark, width int, height int) (string, error) {
return imageprocessor.WatermarkImageAsURL(conv, width, height)
}
func ThumnailsImageAsFile(conv interface{}, width int, height int) ([]byte, error) {
return generate.ThumnailsImageAsFile(conv, width, height)
}
func ThumnailsImageAsURL(conv interface{}, width int, height int) (string, error) {
return generate.ThumnailsImageAsURL(conv, width, height)
}