这是我用于终点的主要功能的一部分
DELETE FROM table_A a
WHERE tbl_id = v_tbl_id
AND NOT EXISTS (SELECT col_id
FROM TABLE(SELECT b.nested_column
FROM table_B b
WHERE tbl_id = v_tbl_id)
WHERE col_id = a.col_id);
但当我r := mux.NewRouter()
r.StrictSlash(true)
r.HandleFunc("/", test)
r.HandleFunc("/feature/list/", a.FeatureListHandler)
log.Fatal(http.ListenAndServe(":8080", r))
时,我
curl localhost:8080/feature/list
然而,当我<a hef="/feature/list">Moved Permanently</a>
时,我得到了我的json。
如何制作它以便两条路线都能返回我想要的json。
答案 0 :(得分:1)
从文档中看,这似乎是StrictSlash
true
时的预期行为:
http://www.gorillatoolkit.org/pkg/mux#Router.StrictSlash
也许您可以将其设置为false
,然后单独定义两条路线?
r.StrictSlash(false)
r.HandleFunc("/feature/list", a.FeatureListHandler)
r.HandleFunc("/feature/list/", a.FeatureListHandler)
答案 1 :(得分:0)
我使用以下中间件来处理
func suffixMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// remove the trailing slash from our URL Path if it's not root
if r.URL.Path != "/" {
r.URL.Path = strings.TrimSuffix(r.URL.Path, "/")
}
// Call the next handler, which can be another middleware in the chain, or the final handler.
next.ServeHTTP(w, r)
})
}
然后您将路由器通过,例如:
(suffixMiddleware(router))