Refactor existing code to use Godo

This commit is contained in:
Eric Meyer 2017-11-01 09:40:04 -05:00
parent e4fe3e0210
commit 121511f10d
3 changed files with 36 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.idea
Gododir/godobin-*
test_data_dir/
vendor/

35
Gododir/main.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"log"
"github.com/8thlight/vulcanizedb/core"
"github.com/jmoiron/sqlx"
do "gopkg.in/godo.v2"
)
func tasks(p *do.Project) {
p.Task("run", nil, func(context *do.Context) {
ipcPath := context.Args.MayString("", "ipc-path", "i")
port := "5432"
host := "localhost"
databaseName := "vulcanize"
var blockchain core.Blockchain = core.NewGethBlockchain(ipcPath)
blockchain.RegisterObserver(core.BlockchainLoggingObserver{})
pgConfig := "host=" + host + " port=" + port + " dbname=" + databaseName + " sslmode=disable"
db, err := sqlx.Connect("postgres", pgConfig)
if err != nil {
log.Fatalf("Error connecting to DB: %v\n", err)
}
blockchain.RegisterObserver(core.BlockchainDBObserver{Db: db})
blockchain.SubscribeToEvents()
})
}
func main() {
do.Godo(tasks)
}

25
main.go
View File

@ -1,25 +0,0 @@
package main
import (
"flag"
"log"
"github.com/8thlight/vulcanizedb/core"
"github.com/jmoiron/sqlx"
)
func main() {
ipcPath := flag.String("ipcPath", "", "location geth.ipc")
flag.Parse()
var blockchain core.Blockchain = core.NewGethBlockchain(*ipcPath)
blockchain.RegisterObserver(core.BlockchainLoggingObserver{})
pgConfig := "host=localhost port=5432 dbname=vulcanize sslmode=disable"
db, err := sqlx.Connect("postgres", pgConfig)
if err != nil {
log.Fatalf("Error connecting to DB: %v\n", err)
}
blockchain.RegisterObserver(core.BlockchainDBObserver{Db: db})
blockchain.SubscribeToEvents()
}