From ad25e605d48b6025165ffa27a65ec5434a73d7c7 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 24 May 2016 17:27:07 +0200 Subject: [PATCH] Allow OPTIONS and other methods in metrics --- metrics.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/metrics.go b/metrics.go index 6384001..64275e0 100644 --- a/metrics.go +++ b/metrics.go @@ -23,7 +23,9 @@ type Metrics struct { // incRequestsTotal increases the counter for this request method atomically by // one. The method must be one of GET, HEAD, POST, PATCH, DELETE. func (m Metrics) incRequestsTotal(method string) { - atomic.AddUint64(m.RequestsTotal[method], 1) + if ptr, ok := m.RequestsTotal[method]; ok { + atomic.AddUint64(ptr, 1) + } } // incErrorsTotal increases the counter for this error atomically by one. @@ -60,11 +62,12 @@ func (m Metrics) incUploadsTerminated() { func newMetrics() Metrics { return Metrics{ RequestsTotal: map[string]*uint64{ - "GET": new(uint64), - "HEAD": new(uint64), - "POST": new(uint64), - "PATCH": new(uint64), - "DELETE": new(uint64), + "GET": new(uint64), + "HEAD": new(uint64), + "POST": new(uint64), + "PATCH": new(uint64), + "DELETE": new(uint64), + "OPTIONS": new(uint64), }, ErrorsTotal: newErrorsTotalMap(), BytesReceived: new(uint64),