本文整理匯總了Golang中github.com/decred/dcrutil.AppDataDir函數的典型用法代碼示例。如果您正苦於以下問題:Golang AppDataDir函數的具體用法?Golang AppDataDir怎麽用?Golang AppDataDir使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AppDataDir函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
// Only override the handlers for notifications you care about.
// Also note most of these handlers will only be called if you register
// for notifications. See the documentation of the dcrrpcclient
// NotificationHandlers type for more details about each handler.
ntfnHandlers := dcrrpcclient.NotificationHandlers{
OnBlockConnected: func(hash *chainhash.Hash, height int32, time time.Time, vb uint16) {
log.Printf("Block connected: %v (%d) %v %v", hash, height, time, vb)
},
OnBlockDisconnected: func(hash *chainhash.Hash, height int32, time time.Time, vb uint16) {
log.Printf("Block disconnected: %v (%d) %v %v", hash, height, time, vb)
},
}
// Connect to local dcrd RPC server using websockets.
dcrdHomeDir := dcrutil.AppDataDir("dcrd", false)
certs, err := ioutil.ReadFile(filepath.Join(dcrdHomeDir, "rpc.cert"))
if err != nil {
log.Fatal(err)
}
connCfg := &dcrrpcclient.ConnConfig{
Host: "localhost:8334",
Endpoint: "ws",
User: "yourrpcuser",
Pass: "yourrpcpass",
Certificates: certs,
}
client, err := dcrrpcclient.New(connCfg, &ntfnHandlers)
if err != nil {
log.Fatal(err)
}
// Register for block connect and disconnect notifications.
if err := client.NotifyBlocks(); err != nil {
log.Fatal(err)
}
log.Println("NotifyBlocks: Registration Complete")
// Get the current block count.
blockCount, err := client.GetBlockCount()
if err != nil {
log.Fatal(err)
}
log.Printf("Block count: %d", blockCount)
// For this example gracefully shutdown the client after 10 seconds.
// Ordinarily when to shutdown the client is highly application
// specific.
log.Println("Client shutdown in 10 seconds...")
time.AfterFunc(time.Second*10, func() {
log.Println("Client shutting down...")
client.Shutdown()
log.Println("Client shutdown complete.")
})
// Wait until the client either shuts down gracefully (or the user
// terminates the process with Ctrl+C).
client.WaitForShutdown()
}
示例2: cleanAndExpandPath
// cleanAndExpandPath expands environement variables and leading ~ in the
// passed path, cleans the result, and returns it.
func cleanAndExpandPath(path string) string {
// Expand initial ~ to OS specific home directory.
if strings.HasPrefix(path, "~") {
appHomeDir := dcrutil.AppDataDir("gencerts", false)
homeDir := filepath.Dir(appHomeDir)
path = strings.Replace(path, "~", homeDir, 1)
}
// NOTE: The os.ExpandEnv doesn't work with Windows-style %VARIABLE%,
// but they variables can still be expanded via POSIX-style $VARIABLE.
return filepath.Clean(os.ExpandEnv(path))
}
示例3: minUint32
defaultFreeTxRelayLimit = 15.0
defaultBlockMinSize = 0
defaultBlockMaxSize = 375000
blockMaxSizeMin = 1000
blockMaxSizeMax = wire.MaxBlockPayload - 1000
defaultBlockPrioritySize = 20000
defaultGenerate = false
defaultAddrIndex = false
defaultNonAggressive = false
defaultNoMiningStateSync = false
defaultAllowOldVotes = false
defaultSigCacheMaxSize = 50000
)
var (
dcrdHomeDir = dcrutil.AppDataDir("dcrd", false)
defaultConfigFile = filepath.Join(dcrdHomeDir, defaultConfigFilename)
defaultDataDir = filepath.Join(dcrdHomeDir, defaultDataDirname)
knownDbTypes = database.SupportedDBs()
defaultRPCKeyFile = filepath.Join(dcrdHomeDir, "rpc.key")
defaultRPCCertFile = filepath.Join(dcrdHomeDir, "rpc.cert")
defaultLogDir = filepath.Join(dcrdHomeDir, defaultLogDirname)
)
// runServiceCommand is only set to a real function on Windows. It is used
// to parse and execute service commands specified via the -s flag.
var runServiceCommand func(string) error
// minUint32 is a helper function to return the minimum of two uint32s.
// This avoids a math import and the need to cast to floats.
func minUint32(a, b uint32) uint32 {
示例4:
// defaultPubPassphrase is the default public wallet passphrase which is
// used when the user indicates they do not want additional protection
// provided by having all public data in the wallet encrypted by a
// passphrase only known to them.
defaultPubPassphrase = "public"
// maxEmptyAccounts is the number of accounts to scan even if they have no
// transaction history. This is a deviation from BIP044 to make account
// creation easier by allowing a limited number of empty accounts.
maxEmptyAccounts = 100
walletDbName = "wallet.db"
)
var (
dcrdHomeDir = dcrutil.AppDataDir("dcrd", false)
dcrwalletHomeDir = dcrutil.AppDataDir("dcrwallet", false)
dcrdHomedirCAFile = filepath.Join(dcrdHomeDir, "rpc.cert")
defaultConfigFile = filepath.Join(dcrwalletHomeDir, defaultConfigFilename)
defaultDataDir = dcrwalletHomeDir
defaultRPCKeyFile = filepath.Join(dcrwalletHomeDir, "rpc.key")
defaultRPCCertFile = filepath.Join(dcrwalletHomeDir, "rpc.cert")
defaultLogDir = filepath.Join(dcrwalletHomeDir, defaultLogDirname)
)
type config struct {
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
Create bool `long:"create" description:"Create the wallet if it does not exist"`
CreateTemp bool `long:"createtemp" description:"Create a temporary simulation wallet (pass=password) in the data directory indicated; must call with --datadir"`
CreateWatchingOnly bool `long:"createwatchingonly" description:"Create the wallet and instantiate it as watching only with an HD extended pubkey; must call with --create"`
CAFile string `long:"cafile" description:"File containing root certificates to authenticate a TLS connections with dcrd"`
示例5: init
import (
"bufio"
"fmt"
"os"
"path/filepath"
"github.com/btcsuite/go-flags"
"github.com/decred/dcrutil"
"github.com/decred/dcrwallet/walletdb"
_ "github.com/decred/dcrwallet/walletdb/bdb"
)
const defaultNet = "mainnet"
var datadir = dcrutil.AppDataDir("dcrwallet", false)
// Flags.
var opts = struct {
Force bool `short:"f" description:"Force removal without prompt"`
DbPath string `long:"db" description:"Path to wallet database"`
}{
Force: false,
DbPath: filepath.Join(datadir, defaultNet, "wallet.db"),
}
func init() {
_, err := flags.Parse(&opts)
if err != nil {
os.Exit(1)
}
示例6:
package main
import (
"fmt"
"net"
"os"
"path/filepath"
"strings"
"github.com/decred/dcrutil"
flags "github.com/btcsuite/go-flags"
)
var (
dcrdHomeDir = dcrutil.AppDataDir("dcrd", false)
appHomeDir = dcrutil.AppDataDir("checkdevpremine", false)
defaultConfigFile = filepath.Join(appHomeDir, "checkdevpremine.conf")
defaultRPCServer = "localhost"
defaultRPCCertFile = filepath.Join(dcrdHomeDir, "rpc.cert")
)
// config defines the configuration options for dcrctl.
//
// See loadConfig for details on the configuration load process.
type config struct {
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
RPCUser string `short:"u" long:"rpcuser" description:"RPC username"`
RPCPassword string `short:"P" long:"rpcpass" default-mask:"-" description:"RPC password"`
RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"`
RPCCert string `short:"c" long:"rpccert" description:"RPC server certificate chain for validation"`
示例7: fatalf
"github.com/btcsuite/golangcrypto/ssh/terminal"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrjson"
"github.com/decred/dcrd/txscript"
"github.com/decred/dcrd/wire"
"github.com/decred/dcrrpcclient"
"github.com/decred/dcrutil"
"github.com/decred/dcrwallet/internal/cfgutil"
"github.com/decred/dcrwallet/netparams"
"github.com/decred/dcrwallet/wallet/txauthor"
"github.com/decred/dcrwallet/wallet/txrules"
"github.com/jessevdk/go-flags"
)
var (
walletDataDirectory = dcrutil.AppDataDir("dcrwallet", false)
newlineBytes = []byte{'\n'}
)
func fatalf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, format, args...)
os.Stderr.Write(newlineBytes)
os.Exit(1)
}
func errContext(err error, context string) error {
return fmt.Errorf("%s: %v", context, err)
}
// Flags.
var opts = struct {
示例8:
defaultRollbackTest = false
defaultPruneTickets = false
defaultTicketMaxPrice = 0.0
defaultTicketBuyFreq = 1
defaultAutomaticRepair = false
defaultUnsafeMainNet = false
defaultPromptPass = false
defaultAddrIdxScanLen = 750
defaultStakePoolColdExtKey = ""
defaultAllowHighFees = false
walletDbName = "wallet.db"
)
var (
dcrdDefaultCAFile = filepath.Join(dcrutil.AppDataDir("dcrd", false), "rpc.cert")
defaultAppDataDir = dcrutil.AppDataDir("dcrwallet", false)
defaultConfigFile = filepath.Join(defaultAppDataDir, defaultConfigFilename)
defaultRPCKeyFile = filepath.Join(defaultAppDataDir, "rpc.key")
defaultRPCCertFile = filepath.Join(defaultAppDataDir, "rpc.cert")
defaultLogDir = filepath.Join(defaultAppDataDir, defaultLogDirname)
)
type config struct {
// General application behavior
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
Create bool `long:"create" description:"Create the wallet if it does not exist"`
CreateTemp bool `long:"createtemp" description:"Create a temporary simulation wallet (pass=password) in the data directory indicated; must call with --datadir"`
CreateWatchingOnly bool `long:"createwatchingonly" description:"Create the wallet and instantiate it as watching only with an HD extended pubkey; must call with --create"`
AppDataDir string `short:"A" long:"appdata" description:"Application data directory for wallet config, databases and logs"`
示例9:
defaultDBPort = "3306"
defaultDBUser = "stakepool"
defaultListen = ":8000"
defaultPoolEmail = "[email protected]"
defaultPoolFees = 7.5
defaultPoolLink = "https://forum.decred.org/threads/rfp-6-setup-and-operate-10-stake-pools.1361/"
defaultPublicPath = "public"
defaultTemplatePath = "views"
defaultRecaptchaSecret = "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
defaultRecaptchaSitekey = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"
defaultSMTPHost = ""
defaultMinServers = 2
)
var (
dcrstakepoolHomeDir = dcrutil.AppDataDir("dcrstakepool", false)
defaultConfigFile = filepath.Join(dcrstakepoolHomeDir, defaultConfigFilename)
defaultDataDir = filepath.Join(dcrstakepoolHomeDir, defaultDataDirname)
defaultLogDir = filepath.Join(dcrstakepoolHomeDir, defaultLogDirname)
)
// runServiceCommand is only set to a real function on Windows. It is used
// to parse and execute service commands specified via the -s flag.
var runServiceCommand func(string) error
// config defines the configuration options for dcrd.
//
// See loadConfig for details on the configuration load process.
type config struct {
ShowVersion bool `short:"V" long:"version" description:"Display version information and exit"`
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`