From fa5d2994ee34153616eddf3e57fc13d5283faa18 Mon Sep 17 00:00:00 2001 From: Ulysses Aalto Date: Mon, 17 Aug 2015 17:14:48 +0300 Subject: [PATCH] Nicely formatted User Agent list --- .../getlantern/flashlight/logging/useragents.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/github.com/getlantern/flashlight/logging/useragents.go b/src/github.com/getlantern/flashlight/logging/useragents.go index be3d8d12b4..4d8c47efc1 100644 --- a/src/github.com/getlantern/flashlight/logging/useragents.go +++ b/src/github.com/getlantern/flashlight/logging/useragents.go @@ -1,7 +1,9 @@ package logging import ( + "bytes" "fmt" + "regexp" "sync" ) @@ -10,6 +12,7 @@ type agentsMap map[string]int var ( userAgents = make(agentsMap) agentsMutex = &sync.Mutex{} + reg = regexp.MustCompile("^Go.*package http$") ) // registerUserAgent tries to find the User-Agent in the HTTP request @@ -34,5 +37,14 @@ func RegisterUserAgent(agent string) { func GetSessionUserAgents() string { agentsMutex.Lock() defer agentsMutex.Unlock() - return (fmt.Sprintf("%v", userAgents)) + + var buffer bytes.Buffer + + for key, val := range userAgents { + if !reg.MatchString(key) { + buffer.WriteString(key) + buffer.WriteString(fmt.Sprintf(": %d requests; ", val)) + } + } + return string(buffer.String()) }