Skip to content

Commit

Permalink
Merge pull request #5 from go-flexible/feature/improve-defaults
Browse files Browse the repository at this point in the history
feat: add default timeouts to http server
  • Loading branch information
ladydascalie authored Aug 16, 2021
2 parents 05a2bbb + 030579b commit 0d3d931
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion flexmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/http/pprof"
"os"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
)
Expand All @@ -17,6 +18,18 @@ const (

// DefaultPath is the path where we expose prometheus by default.
DefaultPath = "/metrics"

// DefaultReadTimeout is the default read timeout for the http server.
DefaultReadTimeout = 5 * time.Second

// DefaultReadHeaderTimeout is the default read header timeout for the http server.
DefaultReadHeaderTimeout = 1 * time.Second

// DefaultIdleTimeout is the default idle timeout for the http server.
DefaultIdleTimeout = 1 * time.Second

// DefaultWriteTimeout is the default write timeout for the http server.
DefaultWriteTimeout = 15 * time.Second
)

type Option func(s *Server)
Expand Down Expand Up @@ -54,7 +67,11 @@ func New(options ...Option) *Server {
server := &Server{
Path: path,
Server: &http.Server{
Addr: addr,
Addr: addr,
ReadTimeout: DefaultReadTimeout,
ReadHeaderTimeout: DefaultReadHeaderTimeout,
IdleTimeout: DefaultIdleTimeout,
WriteTimeout: DefaultWriteTimeout,
},
}

Expand Down

0 comments on commit 0d3d931

Please sign in to comment.