func setupGlobalConfig() error {
	numNets := 0
	if cfg.TestNet1 {
		numNets++
		activeNetParams = &chaincfg.TestNet1Params
	}
	if cfg.RegressionTest {
		numNets++
		activeNetParams = &chaincfg.RegressionNetParams
	}
	if cfg.SimNet {
		numNets++
		activeNetParams = &chaincfg.SimNetParams
	}
	if numNets > 1 {
		return errors.New("The testnet, regtest, and simnet params " +
			"can't be used together -- choose one of the three")
	}
	if !validDbType(cfg.DbType) {
		str := "The specified database type [%v] is invalid -- " +
			"supported types %v"
		return fmt.Errorf(str, cfg.DbType, knownDbTypes)
	}
	cfg.DataDir = filepath.Join(cfg.DataDir, netName(activeNetParams))
	return nil
}
setupGlobalConfig examine the global configuration options for any conditions
which are invalid as well as performs any addition setup necessary after the
initial parse.
package main
import (
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"github.com/soteria-dag/soterd/chaincfg"
	"github.com/soteria-dag/soterd/database"
	_ "github.com/soteria-dag/soterd/database/ffldb"
	"github.com/soteria-dag/soterd/wire"
	"github.com/soteria-dag/soterd/soterutil"
)
var (
	soterdHomeDir   = soterutil.AppDataDir("soterd", false)
	knownDbTypes    = database.SupportedDrivers()
	activeNetParams = &chaincfg.MainNetParams
	cfg = &config{
		DataDir: filepath.Join(soterdHomeDir, "data"),
		DbType:  "ffldb",
	}
)
type config struct {
	DataDir        string `short:"b" long:"datadir" description:"Location of the soterd data directory"`
	DbType         string `long:"dbtype" description:"Database backend to use for the Block Chain"`
	TestNet1       bool   `long:"testnet" description:"Use the test network"`
	RegressionTest bool   `long:"regtest" description:"Use the regression test network"`
	SimNet         bool   `long:"simnet" description:"Use the simulation test network"`
}
func fileExists(name string) bool {
	if _, err := os.Stat(name); err != nil {
		if os.IsNotExist(err) {
			return false
		}
	}
	return true
}
func validDbType(dbType string) bool {
	for _, knownType := range knownDbTypes {
		if dbType == knownType {
			return true
		}
	}
	return false
}
func netName(chainParams *chaincfg.Params) string {
	switch chainParams.Net {
	case wire.TestNet1:
		return "testnet"
	default:
		return chainParams.Name
	}
}