aboutsummaryrefslogtreecommitdiff
path: root/handler.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-30 20:40:17 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-30 20:40:17 +0100
commitf367d220ff99eaee7debb234c3234de6c781359c (patch)
tree49fda266aaf121e725780d2b7e2d6eb70710c74c /handler.go
parent5426f3bcd1a5ae4fc4b3b831b41c0d667a17e525 (diff)
refactor types and documentation
Structured files a bit better, added more documentation, switched to pointers as default (unless specifically motivated not to do so), and encapsulated TLS (un)marshaling for the respective types that use it.
Diffstat (limited to 'handler.go')
-rw-r--r--handler.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/handler.go b/handler.go
index 675c441..735d798 100644
--- a/handler.go
+++ b/handler.go
@@ -20,7 +20,6 @@ type appHandler struct {
handler func(context.Context, *Instance, http.ResponseWriter, *http.Request) (int, error)
}
-// ServeHTTP docdoc
func (a appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(a.instance.Deadline))
defer cancel()
@@ -38,7 +37,6 @@ func (a appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
-// sendHTTPError replies to a request with an error message and a status code.
func (a appHandler) sendHTTPError(w http.ResponseWriter, statusCode int, err error) {
http.Error(w, http.StatusText(statusCode), statusCode)
}
@@ -69,7 +67,7 @@ func addEntry(ctx context.Context, i *Instance, w http.ResponseWriter, r *http.R
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("failed creating signed debug info: %v", err)
}
- rsp, err := StItemToB64(sdi)
+ rsp, err := sdi.MarshalB64()
if err != nil {
return http.StatusInternalServerError, err
}
@@ -142,7 +140,7 @@ func getProofByHash(ctx context.Context, i *Instance, w http.ResponseWriter, r *
return status, err
}
- rsp, err := StItemToB64(NewInclusionProofV1(i.LogParameters.LogId, uint64(req.TreeSize), trsp.Proof[0]))
+ rsp, err := NewInclusionProofV1(i.LogParameters.LogId, uint64(req.TreeSize), trsp.Proof[0]).MarshalB64()
if err != nil {
return http.StatusInternalServerError, err
}
@@ -173,7 +171,7 @@ func getConsistencyProof(ctx context.Context, i *Instance, w http.ResponseWriter
return status, err
}
- rsp, err := StItemToB64(NewConsistencyProofV1(i.LogParameters.LogId, req.First, req.Second, trsp.Proof))
+ rsp, err := NewConsistencyProofV1(i.LogParameters.LogId, req.First, req.Second, trsp.Proof).MarshalB64()
if err != nil {
return http.StatusInternalServerError, err
}
@@ -205,7 +203,7 @@ func getSth(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Req
if err != nil {
return http.StatusInternalServerError, fmt.Errorf("failed creating signed tree head: %v", err)
}
- rsp, err := StItemToB64(sth)
+ rsp, err := sth.MarshalB64()
if err != nil {
return http.StatusInternalServerError, err
}