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
/
Copy pathmeta.go
82 lines (65 loc) · 1.51 KB
/
meta.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
package tika
import (
"errors"
"net/http"
)
// MetaResource represents the structure of our Meta resource
type MetaResource struct {
client *Client
endpoint string
}
// Meta is the entry point for interacting with the Meta resource
func (c *Client) Meta() *MetaResource {
endpoint := c.Url + "/meta"
if len(c.Key) > 0 {
endpoint += "/" + c.Key
}
return &MetaResource{client: c,
endpoint: endpoint,
}
}
// Raw returns the metadata as bytes
func (mr *MetaResource) Raw() ([]byte, error) {
req, err := mr.newRequest()
if err != nil {
return nil, err
}
return mr.client.raw(req)
}
// Csv returns the metadata as comma-separated values
func (mr *MetaResource) Csv() (string, error) {
req, err := mr.newRequest()
if err != nil {
return "", err
}
return mr.client.csv(req)
}
// Text returns the metadata as plain text
func (mr *MetaResource) Text() (string, error) {
if len(mr.client.Key) < 1 {
return "", errors.New("text requires a key")
}
req, err := mr.newRequest()
if err != nil {
return "", err
}
return mr.client.text(req)
}
// Json returns the metadata as JSON
func (mr *MetaResource) Json() ([]byte, error) {
req, err := mr.newRequest()
if err != nil {
return nil, err
}
return mr.client.json(req)
}
func (mr *MetaResource) newRequest() (*http.Request, error) {
if mr.client.Document == nil {
return nil, errors.New("need a document")
}
req, err := mr.client.NewRequest(http.MethodPut, mr.endpoint, mr.client.Document)
if err != nil {
return nil, err
}
return req, nil
}