aboutsummaryrefslogtreecommitdiff
path: root/handler.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-12-01 20:42:21 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-12-01 20:42:21 +0100
commitb540f681b4cdf740f9b8d1e584fd2b107fc1b090 (patch)
tree26f2f9c3df8a563463c19621cb9f812978c90af3 /handler.go
parent12af3f2e8fad65534b83260967ea7463df6ca652 (diff)
started to clean-up instance
Things like opening files is better place in the server package. Any code that is difficult to test should also not be in the STFE package.
Diffstat (limited to 'handler.go')
-rw-r--r--handler.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/handler.go b/handler.go
index bd1fbdb..58771c8 100644
--- a/handler.go
+++ b/handler.go
@@ -12,16 +12,22 @@ import (
"github.com/google/trillian/types"
)
-// handler implements the http.Handler interface, and contains a reference
+// Handler implements the http.Handler interface, and contains a reference
// to an STFE server instance as well as a function that uses it.
-type handler struct {
+type Handler struct {
instance *Instance // STFE server instance
endpoint Endpoint // e.g., add-entry
method string // e.g., GET
handler func(context.Context, *Instance, http.ResponseWriter, *http.Request) (int, error)
}
-func (a handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+// Path returns a path that should be configured for this handler
+func (h Handler) Path() string {
+ return h.endpoint.Path("", h.instance.LogParameters.Prefix)
+}
+
+// ServeHTTP is part of the http.Handler interface
+func (a Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// export prometheus metrics
var now time.Time = time.Now()
var statusCode int
@@ -47,7 +53,7 @@ func (a handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
-func (a handler) sendHTTPError(w http.ResponseWriter, statusCode int, err error) {
+func (a Handler) sendHTTPError(w http.ResponseWriter, statusCode int, err error) {
http.Error(w, http.StatusText(statusCode), statusCode)
}