mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +08:00
server/http: Fixed build error
This commit is contained in:

committed by
Juan Batiz-Benet

parent
063cb536df
commit
436462c86a
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gorilla/mux"
|
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gorilla/mux"
|
||||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||||
@ -15,18 +14,17 @@ import (
|
|||||||
core "github.com/jbenet/go-ipfs/core"
|
core "github.com/jbenet/go-ipfs/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
type objectHandler struct {
|
type handler struct {
|
||||||
ipfs
|
ipfs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve starts the http server
|
// Serve starts the http server
|
||||||
func Serve(address ma.Multiaddr, node *core.IpfsNode) error {
|
func Serve(address ma.Multiaddr, node *core.IpfsNode) error {
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
objectHandler := &objectHandler{&ipfsHandler{node}}
|
handler := &handler{&ipfsHandler{node}}
|
||||||
apiHandler := &apiHandler{}
|
|
||||||
|
|
||||||
r.HandleFunc("/ipfs/", objectHandler.postHandler).Methods("POST")
|
r.HandleFunc("/ipfs/", handler.postHandler).Methods("POST")
|
||||||
r.PathPrefix("/ipfs/").Handler(objectHandler).Methods("GET")
|
r.PathPrefix("/ipfs/").Handler(handler).Methods("GET")
|
||||||
|
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
|
|
||||||
@ -38,7 +36,7 @@ func Serve(address ma.Multiaddr, node *core.IpfsNode) error {
|
|||||||
return http.ListenAndServe(host, nil)
|
return http.ListenAndServe(host, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *objectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (i *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path[5:]
|
path := r.URL.Path[5:]
|
||||||
|
|
||||||
nd, err := i.ResolvePath(path)
|
nd, err := i.ResolvePath(path)
|
||||||
@ -59,7 +57,7 @@ func (i *objectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
io.Copy(w, dr)
|
io.Copy(w, dr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *objectHandler) postHandler(w http.ResponseWriter, r *http.Request) {
|
func (i *handler) postHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
nd, err := i.NewDagFromReader(r.Body)
|
nd, err := i.NewDagFromReader(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
Reference in New Issue
Block a user