aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiall Sheridan <nsheridan@gmail.com>2016-09-30 21:51:26 -0700
committerNiall Sheridan <nsheridan@gmail.com>2016-09-30 21:51:26 -0700
commitc5ba6d949d6f83a9e26ab6c132449ab5023f552b (patch)
tree11e895c6164225629ab68c06b07946b3b08436ad
parentba54c84be82cd30ce9eb1253b3b1408098892590 (diff)
Use json.NewDecoder to decode json from http
-rw-r--r--client/client.go7
-rw-r--r--cmd/cashierd/handlers_test.go6
-rw-r--r--cmd/cashierd/main.go7
-rw-r--r--server/store/sqldb.go2
4 files changed, 4 insertions, 18 deletions
diff --git a/client/client.go b/client/client.go
index ba5b900..e69f353 100644
--- a/client/client.go
+++ b/client/client.go
@@ -5,7 +5,6 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
- "io/ioutil"
"net/http"
"net/url"
"path"
@@ -67,12 +66,8 @@ func send(s []byte, token, ca string, ValidateTLSCertificate bool) (*lib.SignRes
return nil, fmt.Errorf("Bad response from server: %s", resp.Status)
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
c := &lib.SignResponse{}
- if err := json.Unmarshal(body, c); err != nil {
+ if err := json.NewDecoder(resp.Body).Decode(c); err != nil {
return nil, err
}
return c, nil
diff --git a/cmd/cashierd/handlers_test.go b/cmd/cashierd/handlers_test.go
index 38251ce..a6bd113 100644
--- a/cmd/cashierd/handlers_test.go
+++ b/cmd/cashierd/handlers_test.go
@@ -114,12 +114,8 @@ func TestSignRevoke(t *testing.T) {
if resp.Code != http.StatusOK {
t.Error("Unexpected response")
}
- b, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- t.Error(err)
- }
r := &lib.SignResponse{}
- if err := json.Unmarshal(b, r); err != nil {
+ if err := json.NewDecoder(resp.Body).Decode(r); err != nil {
t.Error(err)
}
if r.Status != "ok" {
diff --git a/cmd/cashierd/main.go b/cmd/cashierd/main.go
index 6e52ddf..88f190e 100644
--- a/cmd/cashierd/main.go
+++ b/cmd/cashierd/main.go
@@ -10,7 +10,6 @@ import (
"fmt"
"html/template"
"io"
- "io/ioutil"
"log"
"net"
"net/http"
@@ -125,11 +124,7 @@ func (a *appContext) login(w http.ResponseWriter, r *http.Request) (int, error)
// parseKey retrieves and unmarshals the signing request.
func parseKey(r *http.Request) (*lib.SignRequest, error) {
var s lib.SignRequest
- body, err := ioutil.ReadAll(r.Body)
- if err != nil {
- return nil, err
- }
- if err := json.Unmarshal(body, &s); err != nil {
+ if err := json.NewDecoder(r.Body).Decode(&s); err != nil {
return nil, err
}
return &s, nil
diff --git a/server/store/sqldb.go b/server/store/sqldb.go
index 81784b0..f65f601 100644
--- a/server/store/sqldb.go
+++ b/server/store/sqldb.go
@@ -132,7 +132,7 @@ func (db *sqldb) SetRecord(rec *CertRecord) error {
if err := db.conn.Ping(); err != nil {
return err
}
- _, err = db.set.Exec(rec.KeyID, string(principals), rec.CreatedAt, rec.Expires, rec.Raw)
+ _, err = db.set.Exec(rec.KeyID, principals, rec.CreatedAt, rec.Expires, rec.Raw)
return err
}