better logging and error handling

This commit is contained in:
Jeromy 2016-07-13 03:59:27 -07:00
parent 1557895e85
commit 4961bc81bf
2 changed files with 19 additions and 8 deletions

View File

@ -2,31 +2,36 @@ package main
import (
"io"
"log"
"net/http"
"strings"
)
// ipfsHandlerFunc implements a basic 'pass through' proxy for an ipfs daemon
func (c *Cluster) ipfsHandlerFunc(w http.ResponseWriter, r *http.Request) {
path := strings.Split(r.URL.Path, "/")[1:]
if len(path) == 0 {
w.WriteHeader(404)
path := r.URL.Path[8:]
switch path {
case "pin/add":
log.Println("pin request")
default:
log.Printf("path: %s", path)
}
_ = path
url := *r.URL
url.Host = "localhost:5001"
url.Scheme = "http"
req, err := http.NewRequest(r.Method, url.String(), r.Body)
if err != nil {
panic(err)
log.Printf("error creating request: ", err)
http.Error(w, "error forwaring request", 501)
return
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
log.Printf("error forwarding request: ", err)
http.Error(w, "error forwaring request", 501)
return
}
for k, v := range resp.Header {

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"net/http"
"os"
"strings"
cli "github.com/codegangsta/cli"
@ -144,4 +145,9 @@ func main() {
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}