- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在玩一个小玩具服务器来学习围棋网络编程。
我的项目目录结构有以下 public
目录:
public\
| style.css
public
和style.css
的权限是r-x
和r--
给所有人。
在 main.go
中,我有以下几行:
router := mux.NewRouter()
router.Handle("/static/",
http.StripPrefix("/static/", http.FileServer(http.Dir("public"))))
log.Fatal(http.ListenAndServe(":3001", router))
每次调用http://localhost:3001/static/style.css
服务器返回 404。
我已经尝试了路径中前导斜线和尾随斜线的所有组合,但没有任何区别。
我在 Ubuntu 15.10 (x64) 上运行 Go v1.5.3。
最佳答案
这是一个示例,说明如何从名为 public
的文件夹中向 /static/
中的文件提供任何请求。
router := mux.NewRouter()
//router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("public"))))
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("public/"))))
log.Fatal(http.ListenAndServe(":3001", router))
关于go - 无法在 Go Gorilla 服务器中提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34830888/
在围棋中,我尝试了简单的数据库连接。我需要进口大猩猩/MUX,但我不能。。我正在使用VS代码。在cd进入我的项目目录之后,我创建了main.go并运行了go get-u githorb.com/Gor
我得到 session ,来 self 曾经使用的 PHP 在服务器端设置一个或多个键及其值,并能够检索或覆盖它,直到 session 过期。 与 gorilla / session 相同 var(
在 Go 中,我尝试了简单的数据库连接。我需要导入 gorilla/mux ,但我做不到。 我正在使用 VS 代码。之后 cd转到我的项目目录,我创建了 main.go确实跑了go get -u gi
尝试使用 github.com/gorilla/mux 配置 go 服务器路由以响应所有带有 index.html 的请求,但排除扩展名为 .jpg|.js|.png 的请求 由于扩展名而被排除的静态
我从表格中收到日期。该日期具有特定格式“dd/mm/yyyy”。 为了将其解析为我的结构,我使用 gorilla/schema 包,但该包无法将接收到的数据识别为日期。 我如何解析日期并将其放入正确的
我有一个客户端的websocket代码看起来像这样 c, _, err := websocket.DefaultDialer.Dial("", nil) if err != nil {
我正在学习 Go 并遇到了 gorilla/mux 路由器。我想在文本文件中有动态路由,例如: /user/1/post/1 为此,我编写了以下代码: func (s *Server) RegRout
因此,我知道 Gorilla Mux 不支持可选的查询参数,人们建议使用查询参数创建不同的路由,从而使其更加牢固。但是在我的情况下,无法按预期的方式解析路线。 如果我调用/service/{local
我正在使用来自 gorilla websockets 的聊天应用程序示例,但我有一个问题,有时,当后端需要向客户端发送两条不同的消息时,它们只在一个消息事件中发送,这对我来说很糟糕,因为JSON.pa
我想通过 gorilla /websocket发送图像数据的字节,我当前的代码是: var b bytes.Buffer empty := bufio.NewWriter(&b) png.Encode
我正在访问一些我以前写的简单Web服务器的旧代码,并且我的请求模式不再起作用。我有一个初始化我的路线的函数,如下所示: func (a *App) InitializeRoutes() { a
我想创建一个/user 子路由器,如下所示 user := app.Router.PathPrefix("/user").Subrouter() user.HandleFunc("/create",
我尝试关闭连接手册(使用 Dark WebSocket Terminal ),但客户端告诉我 1005(无状态 Rcvd) 服务器: ReadLoop: for { mt, message,
我有以下代码: r := mux.NewRouter() r.HandleFunc("/", homeHandler) r.HandleFunc("/login", loginHandler) adm
请看下面我的代码。如您所见,这是一个具有两个端点的简单服务: /test <-- 使用中间件保护的基本身份验证 /static <-- 提供 ./static 目录中的所有文件 现在我也在尝试将基本身
// SetReadLimit sets the maximum size for a message read from the peer. If a // message exceeds the
我有以下路线: router.Methods("POST").Path("/my_post_01").HandlerFunc(myHandler1) router.Methods("GET").Pat
因此,我正在使用 Go 和 Gorilla Mux 开发一个简单的 RESTful API。我的第二条路线不工作时遇到问题,它返回 404 错误。我不确定问题出在哪里,因为我是 Go 和 Gorill
我正在 Golang 中构建一个与 Gorilla websockets 通信的网关。 我在 Ubuntu 16.04 上运行它,目前正在使用 .NET 控制台应用程序对其进行测试。 在 Window
我无法让 gorilla mux 工作.. 当请求 http://www.localhost:9000 时,Web 服务器返回 404 page not found 但这有效 http://local
我是一名优秀的程序员,十分优秀!