Update functions that return error to not return pointer

* Matches Golang convention
This commit is contained in:
Eric Meyer 2017-12-04 10:17:13 -06:00
parent f46891f732
commit 486fdc10e4
7 changed files with 24 additions and 24 deletions

View File

@ -12,7 +12,7 @@ func LoadConfig(environment string) config.Config {
if err != nil {
log.Fatalf("Error loading config\n%v", err)
}
return *cfg
return cfg
}
func LoadPostgres(database config.Database) repositories.Postgres {

View File

@ -24,12 +24,12 @@ var NewErrConfigFileNotFound = func(environment string) error {
return errors.New(fmt.Sprintf("No configuration found for environment: %v", environment))
}
func NewConfig(environment string) (*Config, error) {
func NewConfig(environment string) (Config, error) {
filenameWithExtension := fmt.Sprintf("%s.toml", environment)
absolutePath := filepath.Join(ProjectRoot(), "environments", filenameWithExtension)
config, err := parseConfigFile(absolutePath)
if err != nil {
return nil, NewErrConfigFileNotFound(environment)
return Config{}, NewErrConfigFileNotFound(environment)
} else {
if !filepath.IsAbs(config.Client.IPCPath) {
config.Client.IPCPath = filepath.Join(ProjectRoot(), config.Client.IPCPath)
@ -43,16 +43,16 @@ func ProjectRoot() string {
return path.Join(path.Dir(filename), "..", "..")
}
func parseConfigFile(filePath string) (*Config, error) {
func parseConfigFile(filePath string) (Config, error) {
var cfg Config
_, err := os.Stat(filePath)
if err != nil {
return nil, err
return Config{}, err
} else {
_, err := toml.DecodeFile(filePath, &cfg)
if err != nil {
return nil, err
return Config{}, err
}
return &cfg, err
return cfg, err
}
}

View File

@ -3,7 +3,7 @@ package config_test
import (
"path/filepath"
"github.com/8thlight/vulcanizedb/pkg/config"
cfg "github.com/8thlight/vulcanizedb/pkg/config"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
@ -11,20 +11,20 @@ import (
var _ = Describe("Loading the config", func() {
It("reads the private config using the environment", func() {
privateConfig, err := config.NewConfig("private")
privateConfig, err := cfg.NewConfig("private")
Expect(err).To(BeNil())
Expect(privateConfig.Database.Hostname).To(Equal("localhost"))
Expect(privateConfig.Database.Name).To(Equal("vulcanize_private"))
Expect(privateConfig.Database.Port).To(Equal(5432))
expandedPath := filepath.Join(config.ProjectRoot(), "test_data_dir/geth.ipc")
expandedPath := filepath.Join(cfg.ProjectRoot(), "test_data_dir/geth.ipc")
Expect(privateConfig.Client.IPCPath).To(Equal(expandedPath))
})
It("returns an error when there is no matching config file", func() {
config, err := config.NewConfig("bad-config")
config, err := cfg.NewConfig("bad-config")
Expect(config).To(BeNil())
Expect(config).To(Equal(cfg.Config{}))
Expect(err).NotTo(BeNil())
})

View File

@ -57,11 +57,11 @@ func (blockchain *GethBlockchain) getContractAttributes(contractHash string) (co
return contractAttributes, nil
}
func bindContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) {
func bindContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (bind.BoundContract, error) {
abiFilePath := filepath.Join(config.ProjectRoot(), "contracts", "public", fmt.Sprintf("%s.json", address.Hex()))
parsed, err := ParseAbiFile(abiFilePath)
if err != nil {
return nil, err
return bind.BoundContract{}, err
}
return bind.NewBoundContract(address, parsed, caller, transactor), nil
return *bind.NewBoundContract(address, parsed, caller, transactor), nil
}

View File

@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
)
func GenerateConsoleOutput(summary *ContractSummary) string {
func GenerateConsoleOutput(summary ContractSummary) string {
return fmt.Sprintf(template(),
summary.ContractHash,
summary.NumberOfTransactions,
@ -37,7 +37,7 @@ func transactionToString(transaction *core.Transaction) string {
}
}
func attributesString(summary *ContractSummary) string {
func attributesString(summary ContractSummary) string {
var formattedAttributes string
for _, attribute := range summary.Attributes {
formattedAttributes += formatAttribute(attribute.Name, summary) + "\n" + " "
@ -45,7 +45,7 @@ func attributesString(summary *ContractSummary) string {
return formattedAttributes
}
func formatAttribute(attributeName string, summary *ContractSummary) string {
func formatAttribute(attributeName string, summary ContractSummary) string {
var stringResult string
result := summary.GetStateAttribute(attributeName)
switch t := result.(type) {

View File

@ -21,12 +21,12 @@ var NewContractNotWatchedErr = func(contractHash string) error {
return errors.New(fmt.Sprintf("Contract %v not being watched", contractHash))
}
func NewSummary(blockchain core.Blockchain, repository repositories.Repository, contractHash string) (*ContractSummary, error) {
func NewSummary(blockchain core.Blockchain, repository repositories.Repository, contractHash string) (ContractSummary, error) {
watchedContract := repository.FindWatchedContract(contractHash)
if watchedContract != nil {
return newContractSummary(blockchain, *watchedContract), nil
} else {
return nil, NewContractNotWatchedErr(contractHash)
return ContractSummary{}, NewContractNotWatchedErr(contractHash)
}
}
@ -35,9 +35,9 @@ func (contractSummary ContractSummary) GetStateAttribute(attributeName string) i
return result
}
func newContractSummary(blockchain core.Blockchain, watchedContract core.WatchedContract) *ContractSummary {
func newContractSummary(blockchain core.Blockchain, watchedContract core.WatchedContract) ContractSummary {
contract, _ := blockchain.GetContract(watchedContract.Hash)
return &ContractSummary{
return ContractSummary{
blockChain: blockchain,
Contract: contract,
ContractHash: watchedContract.Hash,

View File

@ -18,7 +18,7 @@ var _ bool = Describe("The watched contract summary", func() {
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "123")
Expect(contractSummary).To(BeNil())
Expect(contractSummary).To(Equal(watched_contracts.ContractSummary{}))
Expect(err).NotTo(BeNil())
})
})
@ -32,7 +32,7 @@ var _ bool = Describe("The watched contract summary", func() {
contractSummary, err := watched_contracts.NewSummary(blockchain, repository, "0x123")
Expect(contractSummary).NotTo(BeNil())
Expect(contractSummary).NotTo(Equal(watched_contracts.ContractSummary{}))
Expect(err).To(BeNil())
})