go-eth-proxy

Transparent proxy server for eth-cache
Info | Log | Files | Refs

main.go (920B)


      1 package main
      2 
      3 import (
      4 	"flag"
      5 	"log"
      6 	"os"
      7 	"net/http"
      8 	"strings"
      9 
     10 	"defalsify.org/go-eth-proxy/rpc/geth"
     11 	"defalsify.org/go-eth-proxy/rpc"
     12 	"defalsify.org/go-eth-proxy/store/lmdb"
     13 
     14 )
     15 
     16 
     17 func main() {
     18 	log.SetOutput(os.Stderr)
     19 	dbpath := flag.String("cachepath", ".", "Path to lmdb data")
     20 	host := flag.String("host", "0.0.0.0", "Remote host")
     21 	port := flag.String("port", "8545", "Remote path")
     22 	flag.Parse()
     23 
     24 	db, err := lmdb.NewStore(*dbpath)
     25 	if err != nil {
     26 		log.Printf("%s", err)
     27 		os.Exit(1)
     28 	}
     29 	defer db.Close()
     30 
     31 	h, err := geth.NewGethBackend(db) //svc, flag.Arg(0))
     32 	if err != nil {
     33 		log.Printf("%s", err)
     34 		os.Exit(1)
     35 	}
     36 
     37 	prx, err := rpc.NewProxyServer(h, flag.Arg(0))
     38 	if err != nil {
     39 		log.Printf("%s", err)
     40 		os.Exit(1)
     41 	}
     42 
     43 	srv := &http.Server{
     44 		Handler: prx,
     45 		Addr: strings.Join([]string{*host, *port}, ":"),
     46 	}
     47 	err = srv.ListenAndServe()
     48 	if err != nil {
     49 		log.Printf("%s", err)
     50 		os.Exit(1)
     51 	}
     52 }