- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
所以我最近遇到了一些麻烦......这是我的代码:
https://gist.github.com/anonymous/af1e6d922ce22597099521a4b2cfa16f
我的问题:我正在尝试提供文件夹中的一些 HTML 文件:./docs/html
。我的文件夹结构:
.
├── docs
│ └── html
│ ├── index.html
│ └── rest.html
└── main.go
您会在要点中注意到,我在 http.HandlerFunc
ServeDocs 上调用了 ServeHTTP
方法,然后通过路由器(mux.路由器
)。我遇到的问题是由于某种原因,在 localhost:8080/
提供的唯一文件是 index.html
,当我导航到 localhost 时: 8080/rest.html
我收到 404。
真正奇怪的是,当我删除所有路由器代码并执行如下操作时:
fs := http.FileServer(http.Dir("./docs/html"))
http.Handle("/", fs)
log.Println("Listening...")
http.ListenAndServe(":3000", nil)
一切正常。有人知道发生了什么事吗?我花了几个小时试图解决这个问题,但我终于放弃了。
最佳答案
如果你使用 mux.Router
的 Path
方法,它会起作用
r.Methods(route.Method).Name(route.Name).Handler(handler)
r.Path(route.Pattern)
代替 mux.Route
的 Path
方法(下面有删除线)
r.Methods(route.Method)
.Path(route.Pattern).Name(route.Name).Handler(handler)
我对 gorilla/mux
不太熟悉,所以找不到这背后的确切原因。
关于html - 在 http.HandlerFunc 中调用 http.FileServer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41774588/
我有一个带有 FileServer 函数的 Golang Shell,我希望能够更改 src 目录。这是我所拥有的: func Server() { wdir, _ := os.Getwd()
例如,用户可以将您的 url 与 linux 命令一起放在文件夹/目录中吗? 假设我的服务器包括: bin/ serverfile.go ... public/ index.h
go 核心中的 http 包存在问题。尽管响应正文中的 Content-Length 是正确的,但文件内容似乎已被缓存。在这里演示的是我正在编写的应用程序的简化版本。 package main imp
我有一个简单的文件夹: Test/ main.go Images/ image1.png image2.png index.
在 https://www.alexedwards.net/blog/serving-static-sites-with-go ,有一个静态文件服务器在单个目录中为站点提供服务的示例:static。
上次写了一个2行实现一个静态服务器的文章 今天群里有个哥们是这么写居然返回的是404 见鬼了嘛?? http.handle("/js", http.FileServer
我的 Web 应用程序需要让管理员用户在 .net core 2 应用程序中添加和删除提供的文件夹。我找到了一种提供服务文件夹列表的方法,但我找不到在配置应用程序后动态添加或删除它们的方法。 如何从应
我们有一个服务器应用程序,它将文件从 clientA 中继到 clientB、clientC、clientD 等。我们将这种文件中继称为任务。如果有很多任务在执行,那么CPU使用率会非常非常高。 我想
初学者围棋题 我有这个目录结构。 app_executable html | - index.html data | - static_file.json 我无法让它为 data/stat
我的项目结构如下: /rootfolder index.html main.js main.go 我正在尝试通过 FileServer() 提供静态 javascript 文件
我正在尝试在 Go 中启动一个 HTTP 服务器,它将使用我自己的处理程序来提供我自己的数据,但同时我想使用默认的 http FileServer 来提供文件。 我在使 FileServer 的处理程
http.FileServer 方法属于标准库 net/http,返回一个使用 FileSystem 接口 root 提供文件访问服务的 HTTP 处理器。可以方便的实现静态文件服务器。 http
目录树: . ├── main.go └── web ├── app.go └── views ├── index.html └── js
我在 Go 中使用 http.FileServer 将一些静态文件提供到目录中。 这就是我使用 mux 作为路由器映射它的方式: r.PathPrefix("/download").Handler(h
我使用 http.FileServer 提供来自 dirPath 的 jpeg 图像: http.Handle("/o/", http.StripPrefix( path.Join("/o",
我试图让 Mechanize 登录到 fileserve.com 我已经尝试了下面的代码 require 'rubygems' require 'mechanize' a =
我目前正在使用基本的 http.FileServer设置为提供一个简单的静态站点。我需要使用自定义未找到页面来处理 404 错误。我一直在研究这个问题,但我无法确定最好的解决方案是什么。 我已经看到了
今天我有一台 NAS 服务器在欧洲充当网络服务器、MySQL 和文件服务器,但现在我还需要可以从美国访问它。我的问题是延迟非常慢。我能做些什么来改善这一点 - 我可以以某种方式同步两个 NAS 站,还
我可以将 Netty 与 Resteasy 一起使用或作为 Fileserver : public void file() { ServerBootstrap bootstrap = new
我正在用 Go 制作一个小型独立服务。 UI 需要一些 JS 库,所以我想,我会使用 http.FileServer 来提供来自 node_modules 的 JS 文件 router := chi.
我是一名优秀的程序员,十分优秀!