Refactor of the explorerURL

This commit is contained in:
Martin Boehm 2018-02-26 16:25:40 +01:00
parent d662fa4197
commit d1bf8a60dc
2 changed files with 21 additions and 21 deletions

View File

@ -62,7 +62,7 @@ var (
zeroMQBinding = flag.String("zeromq", "", "binding to zeromq, if missing no zeromq connection") zeroMQBinding = flag.String("zeromq", "", "binding to zeromq, if missing no zeromq connection")
insightWeb = flag.String("insight", "", "address of the insight Bitcoin blockchain explorer") explorerURL = flag.String("explorer", "", "address of the Bitcoin blockchain explorer")
) )
var ( var (
@ -159,7 +159,7 @@ func main() {
var socketIoServer *server.SocketIoServer var socketIoServer *server.SocketIoServer
if *socketIoBinding != "" { if *socketIoBinding != "" {
socketIoServer, err = server.NewSocketIoServer(*socketIoBinding, *certFiles, index, mempool, chain, *insightWeb) socketIoServer, err = server.NewSocketIoServer(*socketIoBinding, *certFiles, index, mempool, chain, *explorerURL)
if err != nil { if err != nil {
glog.Fatal("socketio: ", err) glog.Fatal("socketio: ", err)
} }

View File

@ -17,18 +17,18 @@ import (
// SocketIoServer is handle to SocketIoServer // SocketIoServer is handle to SocketIoServer
type SocketIoServer struct { type SocketIoServer struct {
binding string binding string
certFiles string certFiles string
server *gosocketio.Server server *gosocketio.Server
https *http.Server https *http.Server
db *db.RocksDB db *db.RocksDB
mempool *bchain.Mempool mempool *bchain.Mempool
chain *bchain.BitcoinRPC chain *bchain.BitcoinRPC
insightWeb string explorerURL string
} }
// NewSocketIoServer creates new SocketIo interface to blockbook and returns its handle // NewSocketIoServer creates new SocketIo interface to blockbook and returns its handle
func NewSocketIoServer(binding string, certFiles string, db *db.RocksDB, mempool *bchain.Mempool, chain *bchain.BitcoinRPC, insightWeb string) (*SocketIoServer, error) { func NewSocketIoServer(binding string, certFiles string, db *db.RocksDB, mempool *bchain.Mempool, chain *bchain.BitcoinRPC, explorerURL string) (*SocketIoServer, error) {
server := gosocketio.NewServer(transport.GetDefaultWebsocketTransport()) server := gosocketio.NewServer(transport.GetDefaultWebsocketTransport())
server.On(gosocketio.OnConnection, func(c *gosocketio.Channel) { server.On(gosocketio.OnConnection, func(c *gosocketio.Channel) {
@ -56,14 +56,14 @@ func NewSocketIoServer(binding string, certFiles string, db *db.RocksDB, mempool
} }
s := &SocketIoServer{ s := &SocketIoServer{
binding: binding, binding: binding,
certFiles: certFiles, certFiles: certFiles,
https: https, https: https,
server: server, server: server,
db: db, db: db,
mempool: mempool, mempool: mempool,
chain: chain, chain: chain,
insightWeb: insightWeb, explorerURL: explorerURL,
} }
// support for tests of socket.io interface // support for tests of socket.io interface
@ -110,8 +110,8 @@ func (s *SocketIoServer) Shutdown(ctx context.Context) error {
} }
func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) { func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) {
if s.insightWeb != "" { if s.explorerURL != "" {
http.Redirect(w, r, s.insightWeb+r.URL.Path, 302) http.Redirect(w, r, s.explorerURL+r.URL.Path, 302)
} }
} }