第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

gorilla/mux 請求與 URL 模式不匹配

gorilla/mux 請求與 URL 模式不匹配

Go
不負(fù)相思意 2022-05-18 14:11:57
我正在訪問我前段時(shí)間編寫的簡單網(wǎng)絡(luò)服務(wù)器的一些舊代碼,我的請求模式不再有效。我有一個(gè)初始化我的路由的函數(shù),如下所示:func (a *App) InitializeRoutes() {    a.Router.HandleFunc("/api/forecast/detailed?city={city}&state={state}&period={period}", a.DetailedForecast).Methods("GET")    a.Router.HandleFunc("/api/forecast/detailed?city={city}&state={state}", a.DetailedForecast).Methods("GET")    a.Router.HandleFunc("/api/forecast/detailed?random", a.RandomDetailedForecast).Methods("GET")    a.Router.HandleFunc("/api/forecast/hourly?city={city}&state={state}&hours={hours}", a.HourlyForecast).Methods("GET")    a.Router.HandleFunc("/api/forecast/hourly?city={city}&state={state}", a.HourlyForecast).Methods("GET")    a.Router.NotFoundHandler = http.HandlerFunc(a.Custom404Handler)}我的自定義 404 處理程序只返回一個(gè) {"error": "Not Found"} 的 json從這里開始,我在我的應(yīng)用程序的初始化函數(shù)(底部 3 行)結(jié)束時(shí)初始化這些路由:func (a *App) Initialize() {    var err error    conf.configure()    sqlDataSource := fmt.Sprintf(        "postgres://%s:%s@%s:%s/%s?sslmode=disable",        conf.sqlUsername,        conf.sqlPassword,        conf.sqlHost,        conf.sqlPort,        conf.sqlDbName)    a.DB, err = sql.Open("postgres", sqlDataSource)    if err != nil {        log.Fatal(err)    }    a.Redis = redis.NewClient(&redis.Options{        Addr:     fmt.Sprintf("%s:%s", conf.redisHost, conf.redisPort),        Password: conf.redisPassword,        DB:       conf.redisDb,    })    a.Router = mux.NewRouter()    a.Logger = handlers.CombinedLoggingHandler(os.Stdout, a.Router)    a.InitializeRoutes()}我的應(yīng)用程序在以下功能上運(yùn)行:func (a *App) Run() {    port := fmt.Sprintf(":%s", os.Getenv("SERVER_PORT"))    log.Fatal(http.ListenAndServe(port, a.Logger))}我的服務(wù)器運(yùn)行在:func main() {    a := App{}    a.Initialize()    a.Run()}當(dāng)我嘗試向我所知的有效 URL 模式發(fā)出請求時(shí),我得到以下信息:>>> import requests>>> r = requests.get("http://localhost:8000/api/forecast/detailed?city=Chicago&state=IL")>>> r<Response [404]>>>> r.json(){'error': 'Not Found'}
查看完整描述

1 回答

?
至尊寶的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊

從自述文件...要匹配您需要使用的查詢


r := mux.NewRouter()

...

r.Queries("key", "value")

匹配 PathPrefix


r.PathPrefix("/products/")

我認(rèn)為您需要將這兩者結(jié)合起來才能實(shí)現(xiàn)您想要的。


查看完整回答
反對 回復(fù) 2022-05-18
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號