Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenny authored Sep 11, 2020
2 parents 612c849 + 29e8f12 commit 67ae8e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ type (
// - form:<key>
// - cookie:<key>
//
// Optional. Default: ${time} - ${ip} - ${status} - ${latency} - ${method} ${path}\n
// Optional. Default: #${pid} - ${time} ${status} - ${latency} ${method} ${path}\n
Format string

// TimeFormat https://programming.guide/go/format-parse-string-time-date-example.html
//
// Optional. Default: 15:04:05
// Optional. Default: 2006/01/02 15:04:05
TimeFormat string

// TimeZone can be specified, such as "UTC" and "America/New_York" and "Asia/Chongqing", etc
Expand Down Expand Up @@ -213,7 +213,7 @@ func logger(config LoggerConfig) fiber.Handler {

var timestamp atomic.Value
timestamp.Store(nowTimeString(config.timeZoneLocation, config.TimeFormat))
// Update date/time every millisecond in a separate go routine
// Update date/time every 750 milliseconds in a separate go routine
if strings.Contains(config.Format, "${time}") {
go func() {
for {
Expand Down
4 changes: 3 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (r *Route) match(path, original string) (match bool, values []string) {
// '*' wildcard matches any path
} else if r.star {
values := getAllocFreeParams(1)
values[0] = original[1:]
if len(original) > 1 {
values[0] = original[1:]
}
return true, values
}
// Does this route have parameters
Expand Down
10 changes: 10 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func Test_Route_Match_Star(t *testing.T) {
body, err = ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, "test", getString(body))

// without parameter
route := Route{
star: true,
path: "/*",
routeParser: routeParser{},
}
match, params := route.match("", "")
utils.AssertEqual(t, true, match)
utils.AssertEqual(t, []string{""}, params)
}

func Test_Route_Match_Root(t *testing.T) {
Expand Down

0 comments on commit 67ae8e7

Please sign in to comment.