diff options
author | Wim <wim@42.be> | 2017-06-06 00:01:05 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-06 00:04:18 +0200 |
commit | 3a183cb218c6812964a70d2e75884ad7071d9c0c (patch) | |
tree | ee0d2492c27e84ace88acfcfdc533545f42ccb21 /vendor/github.com/labstack/echo/cookbook/middleware/server.go | |
parent | 2eecaccd1c77e8990a80e6b4b6ad6b13a9c95896 (diff) | |
download | matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.tar.gz matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.tar.bz2 matterbridge-msglm-3a183cb218c6812964a70d2e75884ad7071d9c0c.zip |
Update vendor
Diffstat (limited to 'vendor/github.com/labstack/echo/cookbook/middleware/server.go')
-rw-r--r-- | vendor/github.com/labstack/echo/cookbook/middleware/server.go | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/vendor/github.com/labstack/echo/cookbook/middleware/server.go b/vendor/github.com/labstack/echo/cookbook/middleware/server.go deleted file mode 100644 index 2f21df50..00000000 --- a/vendor/github.com/labstack/echo/cookbook/middleware/server.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "net/http" - "strconv" - "sync" - "time" - - "github.com/labstack/echo" -) - -type ( - Stats struct { - Uptime time.Time `json:"uptime"` - RequestCount uint64 `json:"requestCount"` - Statuses map[string]int `json:"statuses"` - mutex sync.RWMutex - } -) - -func NewStats() *Stats { - return &Stats{ - Uptime: time.Now(), - Statuses: make(map[string]int), - } -} - -// Process is the middleware function. -func (s *Stats) Process(next echo.HandlerFunc) echo.HandlerFunc { - return func(c echo.Context) error { - if err := next(c); err != nil { - c.Error(err) - } - s.mutex.Lock() - defer s.mutex.Unlock() - s.RequestCount++ - status := strconv.Itoa(c.Response().Status) - s.Statuses[status]++ - return nil - } -} - -// Handle is the endpoint to get stats. -func (s *Stats) Handle(c echo.Context) error { - s.mutex.RLock() - defer s.mutex.RUnlock() - return c.JSON(http.StatusOK, s) -} - -// ServerHeader middleware adds a `Server` header to the response. -func ServerHeader(next echo.HandlerFunc) echo.HandlerFunc { - return func(c echo.Context) error { - c.Response().Header().Set(echo.HeaderServer, "Echo/3.0") - return next(c) - } -} - -func main() { - e := echo.New() - - // Debug mode - e.Debug = true - - //------------------- - // Custom middleware - //------------------- - // Stats - s := NewStats() - e.Use(s.Process) - e.GET("/stats", s.Handle) // Endpoint to get stats - - // Server header - e.Use(ServerHeader) - - // Handler - e.GET("/", func(c echo.Context) error { - return c.String(http.StatusOK, "Hello, World!") - }) - - // Start server - e.Logger.Fatal(e.Start(":1323")) -} |