Skip to content

[bug] Documentation for func (*Route) HeadersRegexp is incorrect #666

@Algebra8

Description

@Algebra8

Describe the bug

The documentation example for func (*Route) HeadersRegexp is incorrect:

r := mux.NewRouter()
r.HeadersRegexp("Content-Type", "application/(text|json)",
          "X-Requested-With", "XMLHttpRequest")

mux.NewRouter() returns *mux.Router but HeadersRegexp is defined on *Route. This is a small mistake and is not a major issue because the next (more verbose) example clarifies the mistake.

However, it's a mistake.

Should be something like:

r := mux.NewRouter().NewRoute()
r.HeadersRegexp("Content-Type", "application/(text|json)",
          "X-Requested-With", "XMLHttpRequest")

Versions

Go version: go version
go version go1.16.4 darwin/amd64

package version: run git rev-parse HEAD inside the repo
91708ff

Steps to Reproduce

How can the bug be triggered?

"Bug" is in documentation; triggered by looking at it.

Expected behavior

What output or behaviour were you expecting instead?

As mentioned above, the example should look like:

r := mux.NewRouter().NewRoute()
r.HeadersRegexp("Content-Type", "application/(text|json)",
          "X-Requested-With", "XMLHttpRequest")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions