dqwmhrxt68679 2015-06-02 16:25
浏览 249
已采纳

golang mux HandleFunc总是404

I try to handle HTTP request using mux instead of standart HandleFunc from net/http, because of reasons. With http it used to work, with mux it doesnt.

import (
    _ "github.com/go-sql-driver/mysql"
    "github.com/gorilla/mux"
    _ "io/ioutil"
    "net/http"
)


func init() {

    mx := mux.NewRouter()

    //create a poll
    mx.HandleFunc("/poll", pollCreate)
    mx.HandleFunc("/poll/{id}", loadPoll)
    mx.HandleFunc("/poll/vote", castVote)

    http.ListenAndServe(":8080", mx)
}

The following POST request

localhost:8080/poll

Results in:

INFO     2015-06-02 16:23:12,219 module.py:718] default: "POST /poll HTTP/1.1" 404 19
  • 写回答

1条回答 默认 最新

  • dongqiya9552 2015-06-02 16:49
    关注

    Found solution.

    Change

    http.ListenAndServe(":8080", mx)
    

    To

    http.Handle("/", mx)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用