aboutsummaryrefslogtreecommitdiff
path: root/client.go
blob: 3674db2e7eadee2cd31864c1b20b9464256285f2 (plain)
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
package acme

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"net/http"
)

func Get(uri string, v interface{}) error {
	resp, err := http.Get(uri)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	return json.Unmarshal(body, v)
}

func Post(uri string, v interface{}) error {
	body, err := json.Marshal(v)
	if err != nil {
		return err
	}
	_, err = http.Post(uri, "application/jose+json", bytes.NewReader(body))
	if err != nil {
		return err
	}
	return nil
}