commands

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RootCmd = &cobra.Command{
		Use:   "memento",
		Short: "Ethereum data and indexer",
		Long:  "Scrape ethereum data from any web3-compatible node and index it into a postgres database",
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			configLoaded := false

			if config != "" {

				abs, err := filepath.Abs(config)
				if err != nil {
					log.Error("Error reading filepath: ", err.Error())
				}

				base := filepath.Base(abs)

				path := filepath.Dir(abs)

				viper.SetConfigName(strings.Split(base, ".")[0])
				viper.AddConfigPath(path)
			}

			viper.AddConfigPath(".")

			if err := viper.ReadInConfig(); err != nil {
				log.Info("Could not load config file. Falling back to args. Error: ", err)
			} else {
				configLoaded = true
			}

			if viper.GetString("db.connection-string") == "" && configLoaded {
				var user, pass string
				if !viper.IsSet("db.user") {
					user = viper.GetString("PG_USER")
				} else {
					user = viper.GetString("db.user")
				}

				if !viper.IsSet("db.password") {
					pass = viper.GetString("PG_PASSWORD")
				} else {
					pass = viper.GetString("db.password")
				}

				p := fmt.Sprintf("host=%s port=%s sslmode=%s dbname=%s user=%s password=%s", viper.GetString("db.host"), viper.GetString("db.port"), viper.GetString("db.sslmode"), viper.GetString("db.dbname"), user, pass)

				viper.Set("db.connection-string", p)
			}

			initLogging()
		},

		Run: func(cmd *cobra.Command, args []string) {

			cmd.HelpFunc()(cmd, args)
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL