Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Andres Virviescas Santana committed Jun 9, 2020
1 parent bbf7915 commit e06e8fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package router

import "github.com/valyala/fasthttp"

// Group returns a new grouped Router.
// Group returns a new group.
// Path auto-correction, including trailing slashes, is enabled by default.
func (g *Group) Group(path string) *Group {
path = g.beginPath + path
Expand Down
4 changes: 2 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
MatchedRoutePathParam = fmt.Sprintf("__matchedRoutePath::%s__", gotils.RandBytes(make([]byte, 15)))
)

// New returns a new initialized Router.
// New returns a new router.
// Path auto-correction, including trailing slashes, is enabled by default.
func New() *Router {
return &Router{
Expand All @@ -35,7 +35,7 @@ func New() *Router {
}
}

// Group returns a new grouped Router.
// Group returns a new group.
// Path auto-correction, including trailing slashes, is enabled by default.
func (r *Router) Group(path string) *Group {
return &Group{
Expand Down
16 changes: 8 additions & 8 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ func TestRouterChaining(t *testing.T) {
}

func TestRouterMutable(t *testing.T) {
handler_1 := func(_ *fasthttp.RequestCtx) {}
handler_2 := func(_ *fasthttp.RequestCtx) {}
handler1 := func(_ *fasthttp.RequestCtx) {}
handler2 := func(_ *fasthttp.RequestCtx) {}

router := New()
router.Mutable(true)
Expand All @@ -330,7 +330,7 @@ func TestRouterMutable(t *testing.T) {
}

for _, method := range httpMethods {
router.Handle(method, "/", handler_1)
router.Handle(method, "/", handler1)
}

for method := range router.trees {
Expand All @@ -350,20 +350,20 @@ func TestRouterMutable(t *testing.T) {

for _, route := range routes {
for _, method := range httpMethods {
router.Handle(method, route, handler_1)
router.Handle(method, route, handler1)
}

for _, method := range httpMethods {
err := catchPanic(func() {
router.Handle(method, route, handler_2)
router.Handle(method, route, handler2)
})

if err == nil {
t.Errorf("Mutable 'false' - Method %s - Route %s - Expected panic", method, route)
}

h, _ := router.Lookup(method, route, nil)
if reflect.ValueOf(h).Pointer() != reflect.ValueOf(handler_1).Pointer() {
if reflect.ValueOf(h).Pointer() != reflect.ValueOf(handler1).Pointer() {
t.Errorf("Mutable 'false' - Method %s - Route %s - Handler updated", method, route)
}
}
Expand All @@ -372,15 +372,15 @@ func TestRouterMutable(t *testing.T) {

for _, method := range httpMethods {
err := catchPanic(func() {
router.Handle(method, route, handler_2)
router.Handle(method, route, handler2)
})

if err != nil {
t.Errorf("Mutable 'true' - Method %s - Route %s - Unexpected panic: %v", method, route, err)
}

h, _ := router.Lookup(method, route, nil)
if reflect.ValueOf(h).Pointer() != reflect.ValueOf(handler_2).Pointer() {
if reflect.ValueOf(h).Pointer() != reflect.ValueOf(handler2).Pointer() {
t.Errorf("Method %s - Route %s - Handler is not updated", method, route)
}
}
Expand Down
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type Router struct {
globalAllowed string
}

// Group is a sub-router to group paths
type Group struct {
router *Router
beginPath string
Expand Down

0 comments on commit e06e8fa

Please sign in to comment.