在使用StrictSlash(true)时,Go Gorrilla Mux将继续使用01重定向,如何返回json(Go Gorrilla Mux will keep redirecting with 01 while using StrictSlash(true), how to return the json)
这是我用于终点的主要功能的一部分
r := () 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>但是,当我curl localhost:8080/feature/list/我得到了我的json。
我怎么做到这两条路线将返回我想要的json。
This is part of my main function that I use for my end points
r := () r.StrictSlash(true) r.HandleFunc("/", test) r.HandleFunc("/feature/list/", a.FeatureListHandler) log.Fatal(http.ListenAndServe(":8080", r))but when I curl localhost:8080/feature/list I get
<a hef="/feature/list">Moved Permanently</a>However, when I curl localhost:8080/feature/list/ I get my json.
How do I make it so that both routes will return the json I want.
最满意答案
从文档中,似乎这是StrictSlash为true时的预期行为:
http://www./pkg/mux#Router.StrictSlash
也许您可以将其设置为false然后单独定义两个路由?
r.StrictSlash(false) r.HandleFunc("/feature/list", a.FeatureListHandler) r.HandleFunc("/feature/list/", a.FeatureListHandler)From the docs, it seems this is the expected behaviour for when StrictSlash is true:
http://www./pkg/mux#Router.StrictSlash
Perhaps you can set it to false and then define both routes separately?
r.StrictSlash(false) r.HandleFunc("/feature/list", a.FeatureListHandler) r.HandleFunc("/feature/list/", a.FeatureListHandler)#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
推荐阅读
留言与评论(共有 14 条评论) |
本站网友 黄甘霖 | 15分钟前 发表 |
test) r.HandleFunc("/feature/list/" | |
本站网友 搜索量 | 28分钟前 发表 |
Go Gorrilla Mux将继续使用01重定向 | |
本站网友 木子美的微博 | 29分钟前 发表 |
我怎么做到这两条路线将返回我想要的json | |
本站网友 龚新月 | 25分钟前 发表 |
a.FeatureListHandler) r.HandleFunc("/feature/list/" | |
本站网友 方正集团招聘 | 30分钟前 发表 |
= () r.StrictSlash(true) r.HandleFunc("/" | |
本站网友 小恶魔 | 13分钟前 发表 |
当我curl localhost | |
本站网友 徐州三院 | 22分钟前 发表 |
8080" | |
本站网友 伊美尔幸福医院 | 15分钟前 发表 |
8080" | |
本站网友 全球四大会计师事务所 | 17分钟前 发表 |
8080/feature/list我得到了 <a hef="/feature/list">Moved Permanently</a> 但是 | |
本站网友 蒲公英茶哪些人不宜喝 | 27分钟前 发表 |
8080/feature/list我得到了 <a hef="/feature/list">Moved Permanently</a> 但是 | |
本站网友 七夕网 | 23分钟前 发表 |
我怎么做到这两条路线将返回我想要的json | |
本站网友 大唐军品 | 9分钟前 发表 |
r)) 但当我curl localhost | |
本站网友 樱花卫厨 | 7分钟前 发表 |
= () r.StrictSlash(true) r.HandleFunc("/" |