Back to godoc.org

Package commands

v1.2.0
Latest Go to latest

The latest major version is .

Published: May 8, 2020 | License: MIT | Module: github.com/Alethio/memento

Index

Variables

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)
		},
	}
)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier