From 6cd12911f4d3aa4c6a75c922f9de231e2cf309dd Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 1 Dec 2020 15:34:55 +0100 Subject: attached url method on endpoint type --- instance.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'instance.go') diff --git a/instance.go b/instance.go index 8a0007a..55b23fc 100644 --- a/instance.go +++ b/instance.go @@ -28,6 +28,12 @@ const ( EndpointGetSth = Endpoint("get-sth") ) +// Url builds an endpoint url from a number of components, e.g., base and prefix +func (e Endpoint) Url(components ...string) string { + components = append(components, string(e)) + return strings.Join(components, "/") +} + // Instance is an instance of a particular log front-end type Instance struct { LogParameters *LogParameters @@ -116,27 +122,27 @@ func (i *Instance) registerHandlers(mux *http.ServeMux) { handler handler }{ { - strings.Join([]string{"", i.LogParameters.Prefix, string(EndpointAddEntry)}, "/"), + EndpointAddEntry.Url("", i.LogParameters.Prefix), handler{instance: i, handler: addEntry, endpoint: EndpointAddEntry, method: http.MethodPost}, }, { - strings.Join([]string{"", i.LogParameters.Prefix, string(EndpointGetEntries)}, "/"), + EndpointGetEntries.Url("", i.LogParameters.Prefix), handler{instance: i, handler: getEntries, endpoint: EndpointGetEntries, method: http.MethodGet}, }, { - strings.Join([]string{"", i.LogParameters.Prefix, string(EndpointGetAnchors)}, "/"), + EndpointGetAnchors.Url("", i.LogParameters.Prefix), handler{instance: i, handler: getAnchors, endpoint: EndpointGetAnchors, method: http.MethodGet}, }, { - strings.Join([]string{"", i.LogParameters.Prefix, string(EndpointGetProofByHash)}, "/"), + EndpointGetProofByHash.Url("", i.LogParameters.Prefix), handler{instance: i, handler: getProofByHash, endpoint: EndpointGetProofByHash, method: http.MethodGet}, }, { - strings.Join([]string{"", i.LogParameters.Prefix, string(EndpointGetConsistencyProof)}, "/"), + EndpointGetConsistencyProof.Url("", i.LogParameters.Prefix), handler{instance: i, handler: getConsistencyProof, endpoint: EndpointGetConsistencyProof, method: http.MethodGet}, }, { - strings.Join([]string{"", i.LogParameters.Prefix, string(EndpointGetSth)}, "/"), + EndpointGetSth.Url("", i.LogParameters.Prefix), handler{instance: i, handler: getSth, endpoint: EndpointGetSth, method: http.MethodGet}, }, } { -- cgit v1.2.3