Skip to content

why is NoMethod marked as TODO #2871

@togettoyou

Description

@togettoyou

Description

What is the role of NoMethod , it does not seem to be effective

I found it is marked as TODO :

// NoMethod sets the handlers called when... TODO.
func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
	engine.noMethod = handlers
	engine.rebuild405Handlers()
}

How to reproduce

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	r := gin.Default()
	r.NoRoute(func(c *gin.Context) {
		c.String(http.StatusOK, "NoRoute")
	})
	r.NoMethod(func(c *gin.Context) {
		fmt.Println("NoMethod")
		c.String(http.StatusOK, "NoMethod")
	})
	r.POST("/", func(c *gin.Context) {
		c.String(http.StatusOK, "/")
	})
	r.Run(":8080")
}

Expectations

$ curl http://localhost:8080
NoMethod

$ curl -X POST http://localhost:8080
/

$ curl -X PUT http://localhost:8080
NoMethod

Actual result

$ curl http://localhost:8080
NoRoute

$ curl -X POST http://localhost:8080
/

$ curl -X PUT http://localhost:8080
NoRoute

Environment

  • go version: go version go1.17 windows/amd64
  • gin version (or commit ref): v1.7.4
  • operating system: windows/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions