Browse Source

Added as default middleware and removed ip for now

pull/545/head
Weslei Juan Novaes Pereira 6 years ago
parent
commit
9d3b8585b4
  1. 7
      .idea/workspace.xml
  2. 7
      go.mod
  3. 2
      go.sum
  4. 6
      logger.go
  5. 5
      mux.go

7
.idea/workspace.xml

@ -2,7 +2,9 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b10d9bd6-ec23-43f3-bef7-13a524307117" name="Default Changelist" comment=""> <list default="true" id="b10d9bd6-ec23-43f3-bef7-13a524307117" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" /> <change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -34,6 +36,11 @@
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" /> <property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
</component> </component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\movidesk\mux\main" />
</key>
</component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
<list> <list>

7
go.mod

@ -1,5 +1,8 @@
module github.com/gorilla/mux module gorilla/mux
go 1.12 go 1.12
require github.com/stretchr/testify v1.4.0 require (
github.com/gorilla/mux v1.7.3
github.com/stretchr/testify v1.4.0
)

2
go.sum

@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

6
logger.go

@ -32,8 +32,6 @@ type LogFormatterParams struct {
StatusCode int StatusCode int
// Latency is how much time the server cost to process a certain request. // Latency is how much time the server cost to process a certain request.
Latency time.Duration Latency time.Duration
// ClientIP equals Context's ClientIP method.
ClientIP string
// Method is the HTTP method given to the request. // Method is the HTTP method given to the request.
Method string Method string
// Path is a path the client requests. // Path is a path the client requests.
@ -123,7 +121,6 @@ func LoggerWithConfig(c LogConfig) MiddlewareFunc {
Request: r, Request: r,
TimeStamp: stop, TimeStamp: stop,
Latency: stop.Sub(start), Latency: stop.Sub(start),
ClientIP: "",
Method: r.Method, Method: r.Method,
StatusCode: sw.status, StatusCode: sw.status,
Path: path, Path: path,
@ -143,11 +140,10 @@ func formatter(p LogFormatterParams) string {
p.Latency = p.Latency - p.Latency%time.Second p.Latency = p.Latency - p.Latency%time.Second
} }
return fmt.Sprintf("[MUX] %v |%s %3d %s| %13v | %15s |%s %-7s %s %s\n", return fmt.Sprintf("[MUX] %v |%s %3d %s| %13v |%s %-7s %s %s\n",
p.TimeStamp.Format("2006/01/02 - 15:04:05"), p.TimeStamp.Format("2006/01/02 - 15:04:05"),
statusColor, p.StatusCode, resetColor, statusColor, p.StatusCode, resetColor,
p.Latency, p.Latency,
p.ClientIP,
methodColor, p.Method, resetColor, methodColor, p.Method, resetColor,
p.Path, p.Path,
) )

5
mux.go

@ -23,7 +23,10 @@ var (
// NewRouter returns a new router instance. // NewRouter returns a new router instance.
func NewRouter() *Router { func NewRouter() *Router {
return &Router{namedRoutes: make(map[string]*Route)} r := &Router{namedRoutes: make(map[string]*Route)}
r.Use(Logger)
return r
} }
// Router registers routes to be matched and dispatches a handler. // Router registers routes to be matched and dispatches a handler.

Loading…
Cancel
Save