From 32215b65656e77c2064fd0f0318bbc30ca96ce29 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 10 Dec 2015 14:17:23 +0100 Subject: WIP --- client.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'client.go') diff --git a/client.go b/client.go index b144e6f..238543c 100644 --- a/client.go +++ b/client.go @@ -4,26 +4,25 @@ import ( "bytes" "encoding/json" "errors" - "log" "net/http" "net/textproto" "regexp" "time" - - "github.com/square/go-jose" ) +// Solver decribes a solving interface type Solver interface { Solve() } -type Signer interface { - Sign([]byte, jose.NonceSource) ([]byte, error) -} +// Links to the next stage +type Links map[string]string +// Client ... type Client struct { Dir Directory nonce chan string + Links Links } // NewClient fetches directory and initializes nonce @@ -71,7 +70,7 @@ func (c Client) Nonce() (string, error) { // Post is used for // new-reg, new-authz, challenge, new-cert -func (c Client) Post(s Signer, uri string, v interface{}) (*http.Response, error) { +func (c *Client) Post(s Signer, uri string, v interface{}) (*http.Response, error) { body, err := json.Marshal(v) if err != nil { return nil, err @@ -89,19 +88,16 @@ func (c Client) Post(s Signer, uri string, v interface{}) (*http.Response, error } c.nonce <- replyNonce(resp) + c.Links = links(resp) if resp.StatusCode >= http.StatusBadRequest { return nil, handleError(resp) } - log.Printf("%+v\n", link(resp)) - return resp, nil } -type Links map[string]string - -func link(r *http.Response) Links { +func links(r *http.Response) Links { links := make(Links) key := textproto.CanonicalMIMEHeaderKey("Link") reg := regexp.MustCompile(`^<(.*)>;rel="(.*)"`) -- cgit v1.2.3