duanjianlu0506 2017-04-21 17:51
浏览 39
已采纳

使用大猩猩/ mux golang库时出现404错误

I am fairly new to golang and am finding myself frustrated with a simple file service program. I am suspecting that there is something wrong with my file prefix/ directory in the handler for my router r. I have tried many different formats for the directory. the html file i would like serviced is $HOME/Documents/TEST/Login on my system. Below is my code, note the {address} replaces the ip address.

    package main

    import (
       "log"
       "github.com/gorilla/mux"
       "net/http"
       "time"
     )

   func main() {
   r := mux.NewRouter()
   r.PathPrefix("/Login/").Handler(http.StripPrefix("/Login/", 
   http.FileServer(http.Dir("$HOME/Documents/TEST/Login"))))

   srv := &http.Server{
       Handler:      r,
       Addr:         "{address}:9999",
       WriteTimeout: 600 * time.Second,
       ReadTimeout:  600 * time.Second,
   }

   log.Fatal(srv.ListenAndServe())
   }
  • 写回答

1条回答 默认 最新

  • dswe30290 2017-04-21 17:54
    关注

    Go won't interpret $HOME. Use an explicit path such as /home/username/Documents/TEST/Login/.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败