simple, without retriing

This commit is contained in:
Rekby 2016-04-11 11:43:32 +03:00
parent 334ebd6ee6
commit 3ab9b75696

View file

@ -9,14 +9,10 @@ import (
"fmt"
"net/http"
"errors"
"gopkg.in/square/go-jose.v1"
"time"
"errors"
)
const TRY_COUNT = 10
const RETRY_PAUSE = time.Second
type jws struct {
directoryURL string
privKey crypto.PrivateKey
@ -101,24 +97,14 @@ func (j *jws) getNonce() error {
func (j *jws) Nonce() (string, error) {
nonce := ""
if len(j.nonces) == 0 {
for i := 0; i < TRY_COUNT; i++ {
err := j.getNonce()
if err != nil {
return nonce, err
}
if len(j.nonces) != 0 {
// get nonce ok and can continue
break
}
if i < TRY_COUNT-1 {
time.Sleep(RETRY_PAUSE)
}
err := j.getNonce()
if err != nil {
return nonce, err
}
}
if len(j.nonces) == 0 {
return "", errors.New("Can't get nonce")
}
nonce, j.nonces = j.nonces[len(j.nonces)-1], j.nonces[:len(j.nonces)-1]
return nonce, nil
}