aboutsummaryrefslogtreecommitdiff
path: root/instance.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-12-01 15:34:55 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-12-01 15:34:55 +0100
commit6cd12911f4d3aa4c6a75c922f9de231e2cf309dd (patch)
treea5a39e7e41d4354b8489ae531435c032870ded56 /instance.go
parent7fd9d2f727a8acf43bb6312888c1450ed2a1eb60 (diff)
attached url method on endpoint type
Diffstat (limited to 'instance.go')
-rw-r--r--instance.go18
1 files changed, 12 insertions, 6 deletions
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},
},
} {