From d99f7e60d88d0b76be0384f92fdbeaf6ebbcf80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 28 Mar 2017 09:14:58 -0700 Subject: [PATCH] Don't create http.FileServer on every favicon request Setup it once and use for all requests --- views.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/views.go b/views.go index bd9d74cc2..3f08a47c4 100644 --- a/views.go +++ b/views.go @@ -4,9 +4,6 @@ import ( "crypto/sha1" "encoding/json" "fmt" - "github.com/cloudflare/unsee/config" - "github.com/cloudflare/unsee/models" - "github.com/cloudflare/unsee/store" "io" "net/http" "sort" @@ -14,10 +11,19 @@ import ( "strings" "time" + "github.com/cloudflare/unsee/config" + "github.com/cloudflare/unsee/models" + "github.com/cloudflare/unsee/store" + log "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" ) +var ( + // needed for serving favicon from binary assets + faviconFileServer = http.FileServer(newBinaryFileSystem("static")) +) + func boolInSlice(boolArray []bool, value bool) bool { for _, s := range boolArray { if s == value { @@ -262,7 +268,5 @@ func autocomplete(c *gin.Context) { } func favicon(c *gin.Context) { - fs := newBinaryFileSystem("static") - fileserver := http.FileServer(fs) - fileserver.ServeHTTP(c.Writer, c.Request) + faviconFileServer.ServeHTTP(c.Writer, c.Request) }