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

route mapping works wrong when pattern segments has ":name" type #4

Closed
bigwhite opened this issue May 27, 2017 · 2 comments
Closed

Comments

@bigwhite
Copy link

bigwhite commented May 27, 2017

My test enviroment:
os:

mac os x and ubuntu 16.04

go:

$go version
go version go1.8 darwin/amd64

beego/mux version:

commit 38fddcbf1be964bbc26c0cf7b91157719cfdb56f

test code:

package main

import (
    "log"
    "net/http"

    "github.com/beego/mux"
)

func Register(method string, pattern string, handler http.HandlerFunc) {
    mx.Handler(method, pattern, handler)
}

func addServer(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("addServer"))
}

func getServer(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("getServer"))
}

func delServer(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("delServer"))
}

var mx *mux.Mux

func main() {
    mx = mux.New()

    Register("POST", "/api/v1/servers/:server_name", addServer)
    Register("DELETE", "/api/v1/servers/:server_name", delServer)
    Register("GET", "/api/v1/servers/:server_name", getServer)

    log.Fatal(http.ListenAndServe("127.0.0.1:9999", mx))
}

result:

$curl -X POST  http://127.0.0.1:9999/api/v1/servers/yy-pd.com
addServer

$curl http://127.0.0.1:9999/api/v1/servers/yy-pd.com
"GET" not allowed in "/api/v1/servers/yy-pd.com"

$curl -X DELETE  http://127.0.0.1:9999/api/v1/servers/yy-pd.com
"DELETE" not allowed in "/api/v1/servers/yy-pd.com"

expected: all curl command should return right result.

@astaxie
Copy link
Member

astaxie commented May 27, 2017

thanks, fixed. please try the latest version

@bigwhite
Copy link
Author

problems has been fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants