提交 e2be5c20 作者: Matt Bell 提交者: Juan Batiz-Benet

core/corehttp: Added RedirectOption

上级 b8fcece0
package corehttp
import (
"net/http"
core "github.com/jbenet/go-ipfs/core"
)
func RedirectOption(path string, redirect string) ServeOption {
handler := &redirectHandler{redirect}
return func(n *core.IpfsNode, mux *http.ServeMux) error {
mux.Handle("/"+path, handler)
return nil
}
}
type redirectHandler struct {
path string
}
func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, i.path, 302)
}
package corehttp
import (
"net/http"
// TODO: move to IPNS
const webuiPath = "/ipfs/QmctngrQAt9fjpQUZr7Bx3BsXUcif52eZGTizWhvcShsjz"
core "github.com/jbenet/go-ipfs/core"
)
const (
// TODO rename
webuiPath = "/ipfs/QmTWvqK9dYvqjAMAcCeUun8b45Fwu7wPhEN9B9TsGbkXfJ"
)
func WebUIOption(n *core.IpfsNode, mux *http.ServeMux) error {
mux.Handle("/webui/", &redirectHandler{webuiPath})
return nil
}
type redirectHandler struct {
path string
}
func (i *redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, i.path, 302)
}
var WebUIOption = RedirectOption("webui", webuiPath)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论