Skip to content

Commit dd38e68

Browse files
authored
Merge pull request #32 from terev/master
2 parents bdc839e + 12a2ebf commit dd38e68

File tree

8 files changed

+238
-0
lines changed

8 files changed

+238
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- New middleware helper for the Echo framework
8+
59
## [0.6.1] - 2020-02-07
610

711
### Changed

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The middleware is mainly focused to be compatible with Go std library using http
4242
- [httprouter][httprouter-example]
4343
- [go-restful][gorestful-example]
4444
- [Gin][gin-example]
45+
- [Echo][echo-example]
4546

4647
## Getting Started
4748

@@ -223,5 +224,6 @@ BenchmarkMiddlewareHandler/benchmark_with_predefined_handler_ID-4 1000000
223224
[httprouter-example]: examples/httprouter
224225
[gorestful-example]: examples/gorestful
225226
[gin-example]: examples/gin
227+
[echo-example]: examples/echo
226228
[prometheus-recorder]: metrics/prometheus
227229
[opencensus-recorder]: metrics/opencensus

examples/echo/main.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
10+
"github.com/labstack/echo/v4"
11+
"github.com/prometheus/client_golang/prometheus/promhttp"
12+
13+
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
14+
"github.com/slok/go-http-metrics/middleware"
15+
echoMiddleware "github.com/slok/go-http-metrics/middleware/echo"
16+
)
17+
18+
const (
19+
srvAddr = ":8080"
20+
metricsAddr = ":8081"
21+
)
22+
23+
func main() {
24+
// Create our middleware factory with the default settings.
25+
mdlw := middleware.New(middleware.Config{
26+
Recorder: metrics.NewRecorder(metrics.Config{}),
27+
})
28+
29+
// Create Echo instance and global middleware.
30+
e := echo.New()
31+
e.Use(echoMiddleware.Handler("", mdlw))
32+
33+
// Add our handler.
34+
e.GET("/", func(c echo.Context) error {
35+
return c.String(http.StatusOK, "Hello world")
36+
})
37+
e.GET("/wrong", func(c echo.Context) error {
38+
return c.String(http.StatusTooManyRequests, "oops")
39+
})
40+
41+
// Serve our handler.
42+
go func() {
43+
log.Printf("server listening at %s", srvAddr)
44+
if err := http.ListenAndServe(srvAddr, e); err != nil {
45+
log.Panicf("error while serving: %s", err)
46+
}
47+
}()
48+
49+
// Serve our metrics.
50+
go func() {
51+
log.Printf("metrics listening at %s", metricsAddr)
52+
if err := http.ListenAndServe(metricsAddr, promhttp.Handler()); err != nil {
53+
log.Panicf("error while serving metrics: %s", err)
54+
}
55+
}()
56+
57+
// Wait until some signal is captured.
58+
sigC := make(chan os.Signal, 1)
59+
signal.Notify(sigC, syscall.SIGTERM, syscall.SIGINT)
60+
<-sigC
61+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ require (
55
github.com/emicklei/go-restful v2.11.1+incompatible
66
github.com/gin-gonic/gin v1.5.0
77
github.com/julienschmidt/httprouter v1.3.0
8+
github.com/labstack/echo/v4 v4.1.16
89
github.com/prometheus/client_golang v1.2.1
910
github.com/stretchr/testify v1.4.0
1011
github.com/urfave/negroni v1.0.0

go.sum

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
1818
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1919
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2020
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21+
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
2122
github.com/emicklei/go-restful v2.11.1+incompatible h1:CjKsv3uWcCMvySPQYKxO8XX3f9zD4FeZRsW4G0B4ffE=
2223
github.com/emicklei/go-restful v2.11.1+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
2324
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
@@ -61,10 +62,20 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d
6162
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
6263
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
6364
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
65+
github.com/labstack/echo/v4 v4.1.16 h1:8swiwjE5Jkai3RPfZoahp8kjVCRNq+y7Q0hPji2Kz0o=
66+
github.com/labstack/echo/v4 v4.1.16/go.mod h1:awO+5TzAjvL8XpibdsfXxPgHr+orhtXZJZIQCVjogKI=
67+
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
68+
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
6469
github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=
6570
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
71+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
72+
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
73+
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
74+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
6675
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
6776
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
77+
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
78+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
6879
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
6980
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
7081
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -118,12 +129,19 @@ github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs
118129
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
119130
github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc=
120131
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
132+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
133+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
134+
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
135+
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
136+
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
121137
go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg=
122138
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
123139
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=
124140
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
125141
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
126142
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
143+
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw=
144+
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
127145
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
128146
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
129147
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -135,8 +153,11 @@ golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73r
135153
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
136154
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
137155
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
156+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
138157
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
139158
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
159+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
160+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
140161
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
141162
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
142163
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
@@ -149,14 +170,20 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
149170
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
150171
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
151172
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
173+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
174+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
152175
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
153176
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd h1:r7DufRZuZbWB7j439YfAzP8RPDa9unLkpwQKUYbIMPI=
154177
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
155178
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
156179
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
157180
golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
158181
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
182+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
183+
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
184+
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
159185
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
186+
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
160187
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
161188
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
162189
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

middleware/echo/echo.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Package echo is a helper package to get an echo compatible
2+
// handler/middleware from the standard net/http Middleware factory.
3+
package echo
4+
5+
import (
6+
"net/http"
7+
8+
"github.com/labstack/echo/v4"
9+
"github.com/slok/go-http-metrics/middleware"
10+
)
11+
12+
// Handler returns a Echo compatible middleware from a Middleware factory instance.
13+
// The first handlerID argument is the same argument passed on Middleware.Handler method.
14+
func Handler(handlerID string, m middleware.Middleware) echo.MiddlewareFunc {
15+
// Wrap wrapping handler with echo's WrapMiddleware helper
16+
return echo.WrapMiddleware(func(next http.Handler) http.Handler {
17+
return m.Handler(handlerID, next)
18+
})
19+
}

middleware/echo/echo_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package echo_test
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
8+
"github.com/labstack/echo/v4"
9+
mmetrics "github.com/slok/go-http-metrics/internal/mocks/metrics"
10+
"github.com/slok/go-http-metrics/metrics"
11+
"github.com/slok/go-http-metrics/middleware"
12+
echoMiddleware "github.com/slok/go-http-metrics/middleware/echo"
13+
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/mock"
15+
)
16+
17+
func getTestHandler(statusCode int) echo.HandlerFunc {
18+
return func(context echo.Context) error {
19+
context.Response().WriteHeader(statusCode)
20+
return nil
21+
}
22+
}
23+
24+
func TestMiddlewareIntegration(t *testing.T) {
25+
tests := []struct {
26+
name string
27+
handlerID string
28+
statusCode int
29+
req *http.Request
30+
config middleware.Config
31+
expHandlerID string
32+
expService string
33+
expMethod string
34+
expStatusCode string
35+
}{
36+
{
37+
name: "A default HTTP middleware should call the recorder to measure.",
38+
statusCode: http.StatusAccepted,
39+
req: httptest.NewRequest(http.MethodPost, "/test", nil),
40+
expHandlerID: "/test",
41+
expMethod: http.MethodPost,
42+
expStatusCode: "202",
43+
},
44+
}
45+
46+
for _, test := range tests {
47+
t.Run(test.name, func(t *testing.T) {
48+
assert := assert.New(t)
49+
50+
// Mocks.
51+
mr := &mmetrics.Recorder{}
52+
expHTTPReqProps := metrics.HTTPReqProperties{
53+
ID: test.expHandlerID,
54+
Service: test.expService,
55+
Method: test.expMethod,
56+
Code: test.expStatusCode,
57+
}
58+
expHTTPProps := metrics.HTTPProperties{
59+
ID: test.expHandlerID,
60+
Service: test.expService,
61+
}
62+
mr.On("ObserveHTTPRequestDuration", mock.Anything, expHTTPReqProps, mock.Anything).Once()
63+
mr.On("ObserveHTTPResponseSize", mock.Anything, expHTTPReqProps, mock.Anything).Once()
64+
mr.On("AddInflightRequests", mock.Anything, expHTTPProps, 1).Once()
65+
mr.On("AddInflightRequests", mock.Anything, expHTTPProps, -1).Once()
66+
67+
// Create our echo instance with the middleware.
68+
mdlw := middleware.New(middleware.Config{Recorder: mr})
69+
e := echo.New()
70+
e.POST("/test", getTestHandler(test.statusCode), echoMiddleware.Handler("", mdlw))
71+
72+
// Make the request.
73+
resp := httptest.NewRecorder()
74+
e.ServeHTTP(resp, test.req)
75+
76+
// Check.
77+
mr.AssertExpectations(t)
78+
assert.Equal(test.statusCode, resp.Result().StatusCode)
79+
})
80+
}
81+
}

middleware/echo/example_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package echo_test
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/labstack/echo/v4"
8+
"github.com/prometheus/client_golang/prometheus/promhttp"
9+
10+
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
11+
"github.com/slok/go-http-metrics/middleware"
12+
echoMiddleware "github.com/slok/go-http-metrics/middleware/echo"
13+
)
14+
15+
// EchoMiddleware shows how you would create a default middleware factory and use it
16+
// to create an Echo compatible middleware.
17+
func Example_echoMiddleware() {
18+
// Create our middleware factory with the default settings.
19+
mdlw := middleware.New(middleware.Config{
20+
Recorder: metrics.NewRecorder(metrics.Config{}),
21+
})
22+
23+
// Create our echo instance.
24+
e := echo.New()
25+
26+
// Add our handler and middleware
27+
h := func(c echo.Context) error {
28+
return c.String(http.StatusOK, "Hello world")
29+
}
30+
e.GET("/", h, echoMiddleware.Handler("", mdlw))
31+
32+
// Serve metrics from the default prometheus registry.
33+
log.Printf("serving metrics at: %s", ":8081")
34+
go func() {
35+
_ = http.ListenAndServe(":8081", promhttp.Handler())
36+
}()
37+
38+
// Serve our handler.
39+
log.Printf("listening at: %s", ":8080")
40+
if err := http.ListenAndServe(":8080", e); err != nil {
41+
log.Panicf("error while serving: %s", err)
42+
}
43+
}

0 commit comments

Comments
 (0)