-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_http.go
39 lines (30 loc) · 1007 Bytes
/
client_http.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
package streams
import (
"github.com/benpate/derp"
"github.com/benpate/remote"
)
type DefaultClient struct{}
func NewDefaultClient() Client {
return DefaultClient{}
}
func (client DefaultClient) LoadActor(uri string) (Document, error) {
return client.LoadDocument(uri, map[string]any{})
}
func (client DefaultClient) LoadDocument(uri string, defaultValue map[string]any) (Document, error) {
// Try to load-and-parse the value from the remote server
transaction := remote.Get(uri).
Accept("application/activity+json").
Response(&defaultValue, nil)
if err := transaction.Send(); err != nil {
return NilDocument(), derp.Wrap(err, "hannibal.streams.Client.Load", "Error loading JSON-LD document", uri)
}
header := transaction.ResponseObject.Header
// Return in triumph
return NewDocument(defaultValue,
WithClient(client),
WithMeta("cache-control", header.Get("cache-control")),
WithMeta("etag", header.Get("etag")),
WithMeta("expires", header.Get("expires")),
),
nil
}