Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗑️ Deprecate app.Routes(), introduce app.Stack() #660

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,15 @@ func NewError(code int, message ...string) *Error {
// fmt.Printf("%s\t%s\n", r.Method, r.Path)
// }
func (app *App) Routes() []*Route {
fmt.Println("routes is deprecated since v1.13.2, please use `app.Stack()` to access the raw router stack")
routes := make([]*Route, 0)
for m := range app.stack {
stackLoop:
for r := range app.stack[m] {

// Don't duplicate USE routesCount
if app.stack[m][r].Method == methodUse {
for i := range routes {
if routes[i].Method == methodUse && routes[i].Name == app.stack[m][r].Name {
if routes[i].Method == methodUse && routes[i].Path == app.stack[m][r].Path {
continue stackLoop
}
}
Expand Down Expand Up @@ -512,6 +512,11 @@ func (app *App) Handler() fasthttp.RequestHandler {
return app.handler
}

// Handler returns the server handler.
func (app *App) Stack() [][]*Route {
return app.stack
}

// Shutdown gracefully shuts down the server without interrupting any active connections.
// Shutdown works by first closing all open listeners and then waiting indefinitely for all connections to return to idle and then shut down.
//
Expand Down
4 changes: 2 additions & 2 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (ctx *Ctx) BodyParser(out interface{}) error {
defer decoderPool.Put(schemaDecoder)

// Get content-type
ctype := utils.ToLower(getString(ctx.Fasthttp.Request.Header.ContentType()))
ctype := getString(ctx.Fasthttp.Request.Header.ContentType())

// Parse body accordingly
if strings.HasPrefix(ctype, MIMEApplicationJSON) {
Expand Down Expand Up @@ -799,7 +799,7 @@ func (ctx *Ctx) Render(name string, bind interface{}, layouts ...string) (err er
// Use Templates engine if exist
if ctx.app.Settings.Templates != nil {
// Render template from Templates
fmt.Println("`Templates` are deprecated since v1.11.1, please us `Views` instead")
fmt.Println("render: `Templates` are deprecated since v1.11.1, please us `Views` instead")
if err := ctx.app.Settings.Templates.Render(buf, name, bind); err != nil {
return err
}
Expand Down
5 changes: 0 additions & 5 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type Route struct {
Method string `json:"method"` // HTTP method
Path string `json:"path"` // Original registered route path
Params []string `json:"params"` // Case sensitive param keys
Name string `json:"name"` // Name of first handler used in route
Handlers []Handler `json:"-"` // Ctx handlers
}

Expand Down Expand Up @@ -319,10 +318,6 @@ func (app *App) registerStatic(prefix, root string, config ...Static) Route {
}

func (app *App) addRoute(method string, route *Route) {
// Give name to route if not defined
if route.Name == "" && len(route.Handlers) > 0 {
route.Name = utils.FunctionName(route.Handlers[0])
}
// Get unique HTTP method indentifier
m := methodInt(method)

Expand Down