specify http server binding

This commit is contained in:
Martin Boehm 2018-01-19 00:18:08 +01:00
parent a9bfb59103
commit 8676db1e14
2 changed files with 6 additions and 6 deletions

View File

@ -54,7 +54,7 @@ var (
dryRun = flag.Bool("dryrun", false, "do not index blocks, only download") dryRun = flag.Bool("dryrun", false, "do not index blocks, only download")
parse = flag.Bool("parse", false, "use in-process block parsing") parse = flag.Bool("parse", false, "use in-process block parsing")
startHTTPServer = flag.Bool("httpserver", true, "run http server (default true)") httpServerBinding = flag.String("httpserver", "nil", "http server binding [address]:port, by default no http server")
) )
func main() { func main() {
@ -91,8 +91,8 @@ func main() {
var httpServer *server.HttpServer var httpServer *server.HttpServer
if *startHTTPServer { if *httpServerBinding != "nil" {
httpServer, err = server.New(db) httpServer, err = server.New(*httpServerBinding, db)
if err != nil { if err != nil {
log.Fatalf("https: %s", err) log.Fatalf("https: %s", err)
} }

View File

@ -19,9 +19,9 @@ type HttpServer struct {
db *db.RocksDB db *db.RocksDB
} }
func New(db *db.RocksDB) (*HttpServer, error) { func New(httpServerBinding string, db *db.RocksDB) (*HttpServer, error) {
https := &http.Server{ https := &http.Server{
Addr: ":8333", Addr: httpServerBinding,
} }
s := &HttpServer{ s := &HttpServer{
https: https, https: https,
@ -43,7 +43,7 @@ func New(db *db.RocksDB) (*HttpServer, error) {
// Run starts the server // Run starts the server
func (s *HttpServer) Run() error { func (s *HttpServer) Run() error {
log.Printf("http server starting on port %s", s.https.Addr) log.Printf("http server starting to listen on %s", s.https.Addr)
return s.https.ListenAndServe() return s.https.ListenAndServe()
} }