mirror of
https://github.com/umputun/reproxy.git
synced 2024-11-23 09:27:22 +03:00
lint: minor warns
This commit is contained in:
parent
aef3040b60
commit
f16d92b774
@ -9,12 +9,14 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// Metrics provides registration and middleware for prometheus
|
||||
type Metrics struct {
|
||||
totalRequests *prometheus.CounterVec
|
||||
responseStatus *prometheus.CounterVec
|
||||
httpDuration *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
// NewMetrics create metrics object with all counters registered
|
||||
func NewMetrics() *Metrics {
|
||||
res := &Metrics{}
|
||||
|
||||
@ -55,6 +57,7 @@ func NewMetrics() *Metrics {
|
||||
return res
|
||||
}
|
||||
|
||||
// Middleware for the primary proxy server to publish all counters and update metrics
|
||||
func (m *Metrics) Middleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@ -81,10 +84,12 @@ type responseWriter struct {
|
||||
statusCode int
|
||||
}
|
||||
|
||||
func NewResponseWriter(w http.ResponseWriter) *responseWriter {
|
||||
// NewResponseWriter wraps http.ResponseWriter with stored status code
|
||||
func NewResponseWriter(w http.ResponseWriter) *responseWriter { //nolint golint
|
||||
return &responseWriter{w, http.StatusOK}
|
||||
}
|
||||
|
||||
// WriteHeader wraps http.ResponseWriter and stores status code
|
||||
func (rw *responseWriter) WriteHeader(code int) {
|
||||
rw.statusCode = code
|
||||
rw.ResponseWriter.WriteHeader(code)
|
||||
|
@ -54,7 +54,8 @@ func (s *Server) Run(ctx context.Context) error {
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
httpServer.Shutdown(context.Background())
|
||||
err := httpServer.Shutdown(context.Background())
|
||||
log.Printf("[WARN] mgmt server terminated, %v", err)
|
||||
}()
|
||||
|
||||
return httpServer.ListenAndServe()
|
||||
@ -78,7 +79,7 @@ func (s *Server) routesCtrl() func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
res := map[string][]resp{} // rest.RenderJSON(w, s.Informer.Mappers())
|
||||
res := map[string][]resp{}
|
||||
for _, mp := range s.Informer.Mappers() {
|
||||
res[mp.Server] = append(res[mp.Server], resp{Server: mp.Server, Provider: string(mp.ProviderID), Route: mp.SrcMatch.String(),
|
||||
Destination: mp.Dst, MatchType: mp.MatchType.String(), Ping: mp.PingURL})
|
||||
|
@ -47,6 +47,7 @@ type Matcher interface {
|
||||
Mappers() (mappers []discovery.URLMapper)
|
||||
}
|
||||
|
||||
// Metrics wraps middleware publishing counts
|
||||
type Metrics interface {
|
||||
Middleware(next http.Handler) http.Handler
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user