forked from hartct/toadserver
/
main.go
34 lines (27 loc) · 1014 Bytes
/
main.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
package main
import (
"fmt"
"net/http"
"os"
log "github.com/eris-ltd/toadserver/Godeps/_workspace/src/github.com/Sirupsen/logrus"
logger "github.com/eris-ltd/toadserver/Godeps/_workspace/src/github.com/eris-ltd/common/go/log"
)
func main() {
log.SetFormatter(logger.ErisFormatter{})
log.Warn("Initializing toadserver...")
mux := http.NewServeMux()
mux.HandleFunc("/postfile/", postHandler) //post a file with its contents to gateway, returns hash
//ts makes & signs a nameTx, then posts to a node, which does the broadcasting
mux.HandleFunc("/receiveNameTx/", receiveNameTx) //unpack tx, if valid, add to chain
mux.HandleFunc("/cacheHash/", cacheHash) //also if valid, pin hash on all hosts (except one that sent it :~( )
mux.HandleFunc("/getfile/", getHandler) // request by name, receive contents
http.ListenAndServe(":11113", mux)
}
//-------------------------------------------------------
//--helpers
func ifExit(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}