我在使用 Gorilla 进行路由时遇到问题。对于某些路线,它可以正常工作,但对于其他路线则不行。
我有以下代码:
import (
"github.com/gorilla/mux"
"github.com/justinas/alice"
)
mx.Handle("/register", commonHandlers.ThenFunc(registerUser)).Methods("POST").Name("register") // This works
mx.Handle("/verify", commonHandlers.ThenFunc(verifyUser)).Methods("GET").Name("verify") // Does not work
verifyUser 调用 Verify 函数处理程序只是假设向控制台输出一些内容,例如:
log.Println("This works!")
但是由于某种原因,当我访问example.com/verify时,函数 Verify 从未真正被调用过。奇怪的是,当访问 /verify 时,我的 AngularJS 代码实际上输出了一些东西,但我的 Go 代码没有。
我的 nginx 文件中有以下配置,不确定它是否会与 Gorilla 路由冲突。
server {
listen 80; ## listen for ipv4; this line is default and implied
root /home/usr/go/src/project/dist/;
server_name localhost;
index index.html index.htm;
location @proxy {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
#proxy_pass http://127.0.0.1:3000;
proxy_pass http://127.0.0.1:9000;
}
location / {
try_files $uri.html $uri/ @proxy;
autoindex on;
}
}
我的路由有问题吗?