This repository has been archived by the owner on Dec 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.go
85 lines (69 loc) · 1.86 KB
/
info.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
package tika
import "net/http"
// InfoServices represents the structure of our Info services resource
type InfoServices struct {
client *Client
endpoint string
}
// Info is the entry point for interacting with the Info services
func (c *Client) Info() *InfoServices {
return &InfoServices{client: c,
endpoint: c.Url,
}
}
// Detectors returns the top level Detector to be used, and any child detectors within it.
// Available as plain text, json or human readable HTML
func (is *InfoServices) Detectors() *InfoServices {
is.endpoint += "/detectors"
return is
}
// MimeTypes returns Mime Types, their aliases, their supertype, and the parser.
// Available as plain text, json or human readable HTML
func (is *InfoServices) MimeTypes() *InfoServices {
is.endpoint += "/mime-types"
return is
}
// Parsers returns all the available parsers, along with what mime types they support.
func (is *InfoServices) Parsers() *InfoServices {
is.endpoint += "/parsers/details"
return is
}
// Html returns the info as HTML
func (is *InfoServices) Html() (string, error) {
req, err := is.newRequest()
if err != nil {
return "", err
}
return is.client.html(req)
}
// Json returns the info as JSON
func (is *InfoServices) Json() ([]byte, error) {
req, err := is.newRequest()
if err != nil {
return nil, err
}
return is.client.json(req)
}
// Raw returns the info as bytes
func (is *InfoServices) Raw() ([]byte, error) {
req, err := is.newRequest()
if err != nil {
return nil, err
}
return is.client.raw(req)
}
// Text returns the info as plain text
func (is *InfoServices) Text() (string, error) {
req, err := is.newRequest()
if err != nil {
return "", err
}
return is.client.text(req)
}
func (is *InfoServices) newRequest() (*http.Request, error) {
req, err := is.client.NewRequest(http.MethodGet, is.endpoint, nil)
if err != nil {
return nil, err
}
return req, nil
}