From b540f681b4cdf740f9b8d1e584fd2b107fc1b090 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 1 Dec 2020 20:42:21 +0100 Subject: 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. --- handler.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'handler.go') 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) } -- cgit v1.2.3