-
Notifications
You must be signed in to change notification settings - Fork 8
/
get.go
38 lines (32 loc) · 813 Bytes
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/eris-ltd/toadserver/Godeps/_workspace/src/github.com/eris-ltd/common/go/ipfs"
)
func getHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
//take filename & send ask chain for hash
str := r.URL.Path[1:]
fn := strings.Split(str, "/")
hash := getInfos(fn[1])
err := ipfs.GetFromIPFS(hash, fn[1], "", bytes.NewBuffer([]byte{}))
if err != nil {
fmt.Printf("error getting file from IPFS: %v\n", err)
}
contents, err := ioutil.ReadFile(fn[1])
if err != nil {
fmt.Printf("error reading file: %v\n", err)
}
w.Write(contents)
//or don't remove? & just output like above
err = os.Remove(fn[1])
if err != nil {
fmt.Printf("error removing file: %v\n", err)
}
}
}