aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-11-28 12:52:31 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-11-28 12:52:31 +0100
commit5eca512bccdae709eafb0a8ba4288c12451ac389 (patch)
treeea98aa97de150764386bef4f58c9d463538e87d0 /client.go
parentc68fe908ff33002d7522fd9e26a8f3ea8629426b (diff)
Change nonce provider
Diffstat (limited to 'client.go')
-rw-r--r--client.go20
1 files changed, 4 insertions, 16 deletions
diff --git a/client.go b/client.go
index e99bb74..6e83b5a 100644
--- a/client.go
+++ b/client.go
@@ -6,22 +6,10 @@ import (
"log"
"net/http"
- jose "github.com/square/go-jose"
+ "github.com/square/go-jose"
)
-type Nonce []string
-
-var nonce = Nonce([]string{})
-
-func (n *Nonce) Parse(r *http.Response) {
- nonce := r.Header.Get("Replay-Nonce")
- *n = append(*n, nonce)
-}
-
-func (n Nonce) Nonce() (string, error) {
- last := n[len(n)-1]
- return last, nil
-}
+var nonces = make(nonce, 100) // buffered channel for nonces
func Get(uri string, v interface{}) error {
resp, err := http.Get(uri)
@@ -29,7 +17,7 @@ func Get(uri string, v interface{}) error {
return err
}
defer resp.Body.Close()
- nonce.Parse(resp)
+ nonces.parse(resp)
return json.NewDecoder(resp.Body).Decode(v)
}
@@ -51,7 +39,7 @@ func Post(uri string, v interface{}) error {
func Sign(acc Account, body []byte) (string, error) {
signer, err := jose.NewSigner(jose.RS256, acc.PrivKey)
- signer.SetNonceSource(nonce)
+ signer.SetNonceSource(nonces)
if err != nil {
return "", err
}