本文整理匯總了Golang中github.com/ogier/pflag.BoolVar函數的典型用法代碼示例。如果您正苦於以下問題:Golang BoolVar函數的具體用法?Golang BoolVar怎麽用?Golang BoolVar使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BoolVar函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseFlags
func (cm *ConfigManager) parseFlags() {
pflag.StringVarP(&cm.Flags.ConfigFile, "configfile", "c", DefaultConfigFile, "Path to config")
pflag.StringVarP(&cm.Flags.DestHost, "dest-host", "d", "", "Destination syslog hostname or IP")
pflag.IntVarP(&cm.Flags.DestPort, "dest-port", "p", 0, "Destination syslog port")
if utils.CanDaemonize {
pflag.BoolVarP(&cm.Flags.NoDaemonize, "no-detach", "D", false, "Don't daemonize and detach from the terminal")
} else {
cm.Flags.NoDaemonize = true
}
pflag.StringVarP(&cm.Flags.Facility, "facility", "f", "user", "Facility")
pflag.StringVar(&cm.Flags.Hostname, "hostname", "", "Local hostname to send from")
pflag.StringVar(&cm.Flags.PidFile, "pid-file", "", "Location of the PID file")
// --parse-syslog
pflag.StringVarP(&cm.Flags.Severity, "severity", "s", "notice", "Severity")
// --strip-color
pflag.BoolVar(&cm.Flags.UseTCP, "tcp", false, "Connect via TCP (no TLS)")
pflag.BoolVar(&cm.Flags.UseTLS, "tls", false, "Connect via TCP with TLS")
pflag.BoolVar(&cm.Flags.Poll, "poll", false, "Detect changes by polling instead of inotify")
pflag.Var(&cm.Flags.RefreshInterval, "new-file-check-interval", "How often to check for new files")
_ = pflag.Bool("no-eventmachine-tail", false, "No action, provided for backwards compatibility")
_ = pflag.Bool("eventmachine-tail", false, "No action, provided for backwards compatibility")
pflag.StringVar(&cm.Flags.DebugLogFile, "debug-log-cfg", "", "the debug log file")
pflag.StringVar(&cm.Flags.LogLevels, "log", "<root>=INFO", "\"logging configuration <root>=INFO;first=TRACE\"")
pflag.Parse()
cm.FlagFiles = pflag.Args()
}
示例2: init
func init() {
flag.Usage = printUsage
// set the defaults
defaultSSL = true
defaultPort = 38332
defaultAddress = "localhost"
defaultConfigPath := computeDefaultConfigPath()
flag.StringVarP(&flagConfigPath, "config", "c", defaultConfigPath, "config file path")
flag.StringVarP(&flagUsername, "rpcuser", "u", "", "rpc user name")
flag.StringVarP(&flagPassword, "rpcpassword", "p", "", "rpc password")
flag.BoolVar(&flagSSL, "ssl", defaultSSL, "use secure sockets SSL")
flag.IntVarP(&flagPort, "port", "n", defaultPort, "port number")
flag.StringVarP(&flagAddress, "host", "a", defaultAddress, "server address")
flag.BoolVarP(&verbose, "verbose", "v", false, "verbose output for debugging")
// k , ignore server certificate errors (not recommended, only for testing self-signed certificates")
flag.BoolVar(&flagHelp, "help", false, "Display this information")
flag.BoolVar(&flagVersion, "version", false, "Display version information")
flag.BoolVarP(&flagInsecure, "insecure", "k", false, "Allow connections to servers with 'insecure' SSL connections e.g. self-signed certificates. By default, this option is false, unless the server is localhost or an explicit IP address, in which case the option is true.")
flag.Parse()
flagSetMap = make(map[string]bool)
flag.Visit(visitFlagSetMap)
}
示例3: main
func main() {
var config Config
flag.BoolVar(&DEBUG, "debug", false, "enable debug logging")
flag.BoolVar(&QUIET, "quiet", false, "disable output")
flag.StringVar(&config.FieldSep, "csv-fields-terminated-by", "\t", "field separator")
flag.StringVar(&config.RowSep, "csv-records-terminated-by", "\n", "row separator")
flag.StringVar(&config.NullString, "csv-null-string", "\\N", "output string for NULL values")
flag.BoolVar(&config.DateEpoch, "epoch", true, "output datetime as epoch instead of RFC3339")
defaults_file := flag.String("defaults-file", "my.cnf", "defaults file")
defaults_group_suffix := flag.String("defaults-group-suffix", "", "defaults group suffix")
format := flag.String("format", "json", "output format 'json' or 'csv'")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: mysqlcsvdump [options] database table > output.json\n\n")
fmt.Fprintf(os.Stderr, "Reads connection info from ./my.cnf. Use '-' for table to send query in stdin\n\n")
flag.PrintDefaults()
}
flag.Parse()
args := flag.Args()
if len(args) < 2 {
flag.Usage()
os.Exit(1)
}
dsn := getDSN(*defaults_file, "client"+*defaults_group_suffix, args[0])
rows := getRows(dsn, args[1])
if *format == "json" {
NewJsonWriter(&config).WriteRows(rows)
} else {
NewCsvWriter(&config).WriteRows(rows)
}
}
示例4: init
func init() {
flag.BoolVar(&flagListProtocols, "list-protocols", false,
"list all registered protocols and then exit")
flag.BoolVar(&flagUseTransparent, "transparent", false,
"use transparent proxying (only available on Linux)")
flag.Uint16VarP(&flagListenPort, "port", "p", 0,
"port to listen on")
flag.StringVarP(&flagListenHost, "host", "h", "0.0.0.0",
"host to listen on")
}
示例5: main
// Main entry point
func main() {
// Set defaults for the server configuration with BaseConfiguration
// inside of MyConfiguration.
Conf = &MyConfiguration{
BaseConfiguration: goserv.BaseConfiguration{
BindAddress: "0.0.0.0",
BindPort: 80,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
LogLevel: "debug",
},
Test: false,
}
// Add a flag for our custom Test addition to the Configuration
flag.BoolVar(&Conf.Test, "Test", Conf.Test, "Example of extending the Configuration")
// Simple handler to say hello!
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello!"))
})
// Make a new server.
server := goserv.NewServer(&Conf.BaseConfiguration)
// Log that we are listing
goserv.Logger.Infof("Listening for connections on %s", server.Addr)
// And listen for connections
server.ListenAndServe()
}
示例6: parseArgs
func parseArgs() args {
result := args{}
pflag.Usage = usage
pflag.BoolVarP(&result.options.KeepGoing, "keep-going", "k", false, "")
pflag.BoolVar(&result.options.CheckAll, "check-all", false, "")
pflag.StringVarP(&result.scriptFile, "file", "f", "", "")
verbose := pflag.BoolP("verbose", "v", false, "")
quiet := pflag.BoolP("quiet", "q", false, "")
topics := pflag.String("debug", "", "")
pflag.Parse()
if *topics != "" {
result.debugTopics = strings.Split(*topics, ",")
}
// argh: really, we just want a callback for each occurence of -q
// or -v, which decrements or increments verbosity
if *quiet {
result.verbosity = 0
} else if *verbose {
result.verbosity = 2
} else {
result.verbosity = 1
}
result.options.Targets = pflag.Args()
return result
}
示例7: main
func main() {
var profile, version bool
flag.BoolVarP(&version, "version", "v", false, "\tShow version")
flag.BoolVar(&profile, "profile", false, "\tEnable profiler")
flag.Parse()
InitConfig()
if profile {
f, err := os.Create("alexandria.prof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
// TODO run when there is something new render.GenerateIndex()
if version {
fmt.Println(NAME, VERSION)
return
}
err := qml.Run(run)
if err != nil {
panic(err)
}
}
示例8: main
func main() {
var profile, version bool
flag.BoolVarP(&version, "version", "v", false, "\tShow version")
flag.BoolVar(&profile, "profile", false, "\tEnable profiler")
flag.Parse()
InitConfig()
Config.MaxResults = 20
if profile {
f, err := os.Create("alexandria.prof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
// TODO run GenerateIndex() when there is something new
if version {
fmt.Println(NAME, VERSION)
return
}
http.HandleFunc("/", mainHandler)
http.HandleFunc("/stats", statsHandler)
http.HandleFunc("/search", queryHandler)
http.HandleFunc("/alexandria.edit", editHandler)
serveDirectory("/images/", Config.CacheDirectory)
serveDirectory("/static/", Config.TemplateDirectory+"static")
http.ListenAndServe("127.0.0.1:41665", nil)
}
示例9: init
func init() {
pflag.DurationVar(&config.TickerTime, "ticker-time", 15*time.Minute, "Ticker time.")
pflag.BoolVar(&config.DryRun, "dry-run", true, "Write to STDOUT instead of InfluxDB")
pflag.IntVar(&config.OWMcityID, "owm-city-id", 0, "Open Weather Map city ID")
pflag.IntVar(&config.InfluxPort, "influx-port", 8086, "InfluxDB Port")
pflag.StringVar(&config.InfluxHost, "influx-host", "localhost", "InfluxDB Port")
pflag.StringVar(&config.InfluxUser, "influx-user", "", "InfluxDB User")
pflag.StringVar(&config.InfluxDB, "influx-db", "", "InfluxDB Database")
pflag.StringVar(&config.InfluxPassword, "influx-password", "", "InfluxDB Password")
pflag.StringVar(&config.InfluxRetention, "influx-retention", "default", "InfluxDB Retention")
pflag.StringVar(&config.DhtType, "dht-type", "DHT22", "DHT Type (DHT11, DHT22)")
pflag.IntVar(&config.DhtPin, "dht-pin", 4, "Pin Number DHT Data is connected to")
pflag.BoolVar(&config.DHTPerf, "dht-perf", false, "Run DHT read in Boost Performance Mode - true will result in needing sudo")
pflag.IntVar(&config.DhtRetries, "dht-retries", 15, "Number of reading data retries")
}
示例10: init
func init() {
flag.StringVar(&conf, "conf", "config.toml", "Path of the configuration file")
flag.BoolVar(&version, "version", false, "Return version")
flag.StringVar(&user, "user", "", "User for MariaDB login, specified in the [user]:[password] format")
flag.StringVar(&hosts, "hosts", "", "List of MariaDB hosts IP and port (optional), specified in the host:[port] format and separated by commas")
flag.StringVar(&socket, "socket", "/var/run/mysqld/mysqld.sock", "Path of MariaDB unix socket")
flag.StringVar(&rpluser, "rpluser", "", "Replication user in the [user]:[password] format")
flag.BoolVar(&interactive, "interactive", true, "Ask for user interaction when failures are detected")
flag.BoolVar(&verbose, "verbose", false, "Print detailed execution info")
flag.StringVar(&preScript, "pre-failover-script", "", "Path of pre-failover script")
flag.StringVar(&postScript, "post-failover-script", "", "Path of post-failover script")
flag.Int64Var(&maxDelay, "maxdelay", 0, "Maximum replication delay before initiating failover")
flag.BoolVar(>idCheck, "gtidcheck", false, "Check that GTID sequence numbers are identical before initiating failover")
flag.StringVar(&prefMaster, "prefmaster", "", "Preferred candidate server for master failover, in host:[port] format")
flag.StringVar(&ignoreSrv, "ignore-servers", "", "List of servers to ignore in slave promotion operations")
flag.Int64Var(&waitKill, "wait-kill", 5000, "Wait this many milliseconds before killing threads on demoted master")
flag.BoolVar(&readonly, "readonly", true, "Set slaves as read-only after switchover")
flag.StringVar(&failover, "failover", "", "Failover mode, either 'monitor', 'force' or 'check'")
flag.IntVar(&maxfail, "failcount", 5, "Trigger failover after N failures (interval 1s)")
flag.StringVar(&switchover, "switchover", "", "Switchover mode, either 'keep' or 'kill' the old master.")
flag.BoolVar(&autorejoin, "autorejoin", true, "Automatically rejoin a failed server to the current master.")
flag.StringVar(&logfile, "logfile", "", "Write MRM messages to a log file")
flag.IntVar(&timeout, "connect-timeout", 5, "Database connection timeout in seconds")
flag.IntVar(&faillimit, "failover-limit", 0, "In auto-monitor mode, quit after N failovers (0: unlimited)")
flag.Int64Var(&failtime, "failover-time-limit", 0, "In auto-monitor mode, wait N seconds before attempting next failover (0: do not wait)")
}
示例11: main
func main() {
var index, profile, stats, version bool
flag.BoolVarP(&index, "index", "i", false, "\tUpdate the index")
flag.BoolVarP(&stats, "stats", "S", false, "\tPrint some statistics")
flag.BoolVarP(&version, "version", "v", false, "\tShow version")
flag.BoolVar(&profile, "profile", false, "\tEnable profiler")
flag.Parse()
InitConfig()
Config.MaxResults = 1e9
if profile {
f, err := os.Create("alexandria.prof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
switch {
case index:
GenerateIndex()
case stats:
printStats()
case version:
fmt.Println(NAME, VERSION)
default:
i := 1
if len(os.Args) > 0 {
if os.Args[1] == "--" {
i += 1
} else if os.Args[1] == "all" {
fmt.Printf("Rendered all %d scrolls.\n", RenderAllScrolls())
os.Exit(0)
}
}
results, err := FindScrolls(strings.Join(os.Args[i:], " "))
if err != nil {
panic(err)
}
fmt.Printf("There are %d matching scrolls.\n", len(results.Ids))
for _, id := range results.Ids {
fmt.Println("file://" + Config.CacheDirectory + string(id.Id) + ".png")
}
}
}
示例12: Run
func (mmsd *mmsdService) Run() {
flag.BoolVarP(&mmsd.Verbose, "verbose", "v", mmsd.Verbose, "Set verbosity level")
flag.IPVar(&mmsd.MarathonIP, "marathon-ip", mmsd.MarathonIP, "Marathon endpoint TCP IP address")
flag.UintVar(&mmsd.MarathonPort, "marathon-port", mmsd.MarathonPort, "Marathon endpoint TCP port number")
flag.DurationVar(&mmsd.ReconnectDelay, "reconnect-delay", mmsd.ReconnectDelay, "Marathon reconnect delay")
flag.StringVar(&mmsd.RunStateDir, "run-state-dir", mmsd.RunStateDir, "Path to directory to keep run-state")
flag.StringVar(&mmsd.FilterGroups, "filter-groups", mmsd.FilterGroups, "Application group filter")
flag.IPVar(&mmsd.ManagedIP, "managed-ip", mmsd.ManagedIP, "IP-address to manage for mmsd")
flag.BoolVar(&mmsd.GatewayEnabled, "enable-gateway", mmsd.GatewayEnabled, "Enables gateway support")
flag.IPVar(&mmsd.GatewayAddr, "gateway-bind", mmsd.GatewayAddr, "gateway bind address")
flag.UintVar(&mmsd.GatewayPortHTTP, "gateway-port-http", mmsd.GatewayPortHTTP, "gateway port for HTTP")
flag.UintVar(&mmsd.GatewayPortHTTPS, "gateway-port-https", mmsd.GatewayPortHTTPS, "gateway port for HTTPS")
flag.BoolVar(&mmsd.FilesEnabled, "enable-files", mmsd.FilesEnabled, "enables file based service discovery")
flag.BoolVar(&mmsd.UDPEnabled, "enable-udp", mmsd.UDPEnabled, "enables UDP load balancing")
flag.BoolVar(&mmsd.TCPEnabled, "enable-tcp", mmsd.TCPEnabled, "enables haproxy TCP load balancing")
flag.BoolVar(&mmsd.LocalHealthChecks, "enable-health-checks", mmsd.LocalHealthChecks, "Enable local health checks (if available) instead of relying on Marathon health checks alone.")
flag.StringVar(&mmsd.HaproxyBin, "haproxy-bin", mmsd.HaproxyBin, "path to haproxy binary")
flag.StringVar(&mmsd.HaproxyTailCfg, "haproxy-cfgtail", mmsd.HaproxyTailCfg, "path to haproxy tail config file")
flag.IPVar(&mmsd.ServiceAddr, "haproxy-bind", mmsd.ServiceAddr, "haproxy management port")
flag.UintVar(&mmsd.HaproxyPort, "haproxy-port", mmsd.HaproxyPort, "haproxy management port")
flag.BoolVar(&mmsd.DnsEnabled, "enable-dns", mmsd.DnsEnabled, "Enables DNS-based service discovery")
flag.UintVar(&mmsd.DnsPort, "dns-port", mmsd.DnsPort, "DNS service discovery port")
flag.BoolVar(&mmsd.DnsPushSRV, "dns-push-srv", mmsd.DnsPushSRV, "DNS service discovery to also push SRV on A")
flag.StringVar(&mmsd.DnsBaseName, "dns-basename", mmsd.DnsBaseName, "DNS service discovery's base name")
flag.DurationVar(&mmsd.DnsTTL, "dns-ttl", mmsd.DnsTTL, "DNS service discovery's reply message TTL")
showVersionAndExit := flag.BoolP("version", "V", false, "Shows version and exits")
flag.Usage = func() {
showVersion()
fmt.Fprintf(os.Stderr, "\nUsage: mmsd [flags ...]\n\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n")
}
flag.Parse()
if *showVersionAndExit {
showVersion()
os.Exit(0)
}
mmsd.setupHandlers()
mmsd.setupEventBusListener()
mmsd.setupHttpService()
<-mmsd.quitChannel
}
示例13: parseFlags
func (config *Config) parseFlags() {
// registry
flag.StringVar(&config.Registry.Auth, "registry-auth", "", "Registry basic auth")
flag.StringVar(&config.Registry.Datacenter, "registry-datacenter", "", "Registry datacenter")
flag.StringVar(&config.Registry.Location, "registry", "http://localhost:8500", "Registry location")
flag.StringVar(&config.Registry.Token, "registry-token", "", "Registry ACL token")
flag.BoolVar(&config.Registry.NoVerifySSL, "registry-noverify", false, "don't verify registry SSL certificates")
flag.StringVar(&config.Registry.Prefix, "registry-prefix", "marathon", "prefix for all values sent to the registry")
// Web
flag.StringVar(&config.Web.Listen, "listen", ":4000", "accept connections at this address")
// Marathon
flag.StringVar(&config.Marathon.Location, "marathon-location", "localhost:8080", "marathon URL")
flag.StringVar(&config.Marathon.Protocol, "marathon-protocol", "http", "marathon protocol (http or https)")
flag.StringVar(&config.Marathon.Username, "marathon-username", "", "marathon username for basic auth")
flag.StringVar(&config.Marathon.Password, "marathon-password", "", "marathon password for basic auth")
// General
flag.StringVar(&config.LogLevel, "log-level", "info", "log level: panic, fatal, error, warn, info, or debug")
flag.Parse()
}
示例14: main
func main() {
output := ""
mimetype := ""
filetype := ""
match := ""
siteurl := ""
htmlMinifier := &html.Minifier{}
xmlMinifier := &xml.Minifier{}
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] [input]\n\nOptions:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nInput:\n Files or directories, leave blank to use stdin\n")
}
flag.StringVarP(&output, "output", "o", "", "Output file or directory, leave blank to use stdout")
flag.StringVar(&mimetype, "mime", "", "Mimetype (text/css, application/javascript, ...), optional for input filenames, has precendence over -type")
flag.StringVar(&filetype, "type", "", "Filetype (css, html, js, ...), optional for input filenames")
flag.StringVar(&match, "match", "", "Filename pattern matching using regular expressions, see https://github.com/google/re2/wiki/Syntax")
flag.BoolVarP(&recursive, "recursive", "r", false, "Recursively minify directories")
flag.BoolVarP(&hidden, "all", "a", false, "Minify all files, including hidden files and files in hidden directories")
flag.BoolVarP(&list, "list", "l", false, "List all accepted filetypes")
flag.BoolVarP(&verbose, "verbose", "v", false, "Verbose")
flag.BoolVarP(&watch, "watch", "w", false, "Watch files and minify upon changes")
flag.BoolVarP(&update, "update", "u", false, "Update binary")
flag.StringVar(&siteurl, "url", "", "URL of file to enable URL minification")
flag.BoolVar(&htmlMinifier.KeepDefaultAttrVals, "html-keep-default-attrvals", false, "Preserve default attribute values")
flag.BoolVar(&htmlMinifier.KeepWhitespace, "html-keep-whitespace", false, "Preserve whitespace characters but still collapse multiple whitespace into one")
flag.BoolVar(&xmlMinifier.KeepWhitespace, "xml-keep-whitespace", false, "Preserve whitespace characters but still collapse multiple whitespace into one")
flag.Parse()
rawInputs := flag.Args()
Error = log.New(os.Stderr, "ERROR: ", 0)
if verbose {
Info = log.New(os.Stderr, "INFO: ", 0)
} else {
Info = log.New(ioutil.Discard, "INFO: ", 0)
}
if update {
if err := equinoxUpdate(); err != nil {
Error.Fatalln(err)
}
return
}
if list {
var keys []string
for k := range filetypeMime {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Println(k + "\t" + filetypeMime[k])
}
return
}
usePipe := len(rawInputs) == 0
mimetype = getMimetype(mimetype, filetype, usePipe)
var err error
if match != "" {
pattern, err = regexp.Compile(match)
if err != nil {
Error.Fatalln(err)
}
}
tasks, dirDst, ok := expandInputs(rawInputs)
if !ok {
os.Exit(1)
}
if output != "" {
output = sanitizePath(output)
if dirDst {
if output[len(output)-1] != '/' {
output += "/"
}
if err := os.MkdirAll(output, 0777); err != nil {
Error.Fatalln(err)
}
}
}
if ok = expandOutputs(output, usePipe, &tasks); !ok {
os.Exit(1)
}
m = min.New()
m.AddFunc("text/css", css.Minify)
m.Add("text/html", htmlMinifier)
m.AddFunc("text/javascript", js.Minify)
m.AddFunc("image/svg+xml", svg.Minify)
m.AddFuncRegexp(regexp.MustCompile("[/+]json$"), json.Minify)
m.AddRegexp(regexp.MustCompile("[/+]xml$"), xmlMinifier)
if m.URL, err = url.Parse(siteurl); err != nil {
//.........這裏部分代碼省略.........
示例15: readConfig
func readConfig(parse bool) {
var err error
// Set defaults
ConfigYAML.UDPServiceAddress = defaultUDPServiceAddress
ConfigYAML.TCPServiceAddress = defaultTCPServiceAddress
ConfigYAML.MaxUDPPacketSize = maxUDPPacket
ConfigYAML.BackendType = defaultBackendType
ConfigYAML.PostFlushCmd = "stdout"
ConfigYAML.GraphiteAddress = defaultGraphiteAddress
ConfigYAML.OpenTSDBAddress = defaultOpenTSDBAddress
ConfigYAML.FlushInterval = flushInterval
ConfigYAML.LogLevel = "error"
ConfigYAML.ShowVersion = false
ConfigYAML.DeleteGauges = true
ConfigYAML.ResetCounters = true
ConfigYAML.PersistCountKeys = 0
ConfigYAML.StatsPrefix = statsPrefixName
ConfigYAML.StoreDb = dbPath
ConfigYAML.Prefix = ""
ConfigYAML.ExtraTags = ""
ConfigYAML.PercentThreshold = Percentiles{}
// Percentiles{{Float: 50.0, Str: "50"}, {Float: 80.0, Str: "80"}, {Float: 90.0, Str: "90"}, {Float: 95.0, Str: "95"}}
ConfigYAML.PrintConfig = false
ConfigYAML.LogName = "stdout"
ConfigYAML.LogToSyslog = true
ConfigYAML.SyslogUDPAddress = "localhost:514"
Config = ConfigYAML
os.Setenv("CONFIGOR_ENV_PREFIX", "SD")
configFile = flag.String("config", "", "Configuration file name (warning not error if not exists). Standard: "+configPath)
flag.StringVar(&Config.UDPServiceAddress, "udp-addr", ConfigYAML.UDPServiceAddress, "UDP listen service address")
flag.StringVar(&Config.TCPServiceAddress, "tcp-addr", ConfigYAML.TCPServiceAddress, "TCP listen service address, if set")
flag.Int64Var(&Config.MaxUDPPacketSize, "max-udp-packet-size", ConfigYAML.MaxUDPPacketSize, "Maximum UDP packet size")
flag.StringVar(&Config.BackendType, "backend-type", ConfigYAML.BackendType, "MANDATORY: Backend to use: graphite, opentsdb, external, dummy")
flag.StringVar(&Config.PostFlushCmd, "post-flush-cmd", ConfigYAML.PostFlushCmd, "Command to run on each flush")
flag.StringVar(&Config.GraphiteAddress, "graphite", ConfigYAML.GraphiteAddress, "Graphite service address")
flag.StringVar(&Config.OpenTSDBAddress, "opentsdb", ConfigYAML.OpenTSDBAddress, "OpenTSDB service address")
flag.Int64Var(&Config.FlushInterval, "flush-interval", ConfigYAML.FlushInterval, "Flush interval (seconds)")
flag.StringVar(&Config.LogLevel, "log-level", ConfigYAML.LogLevel, "Set log level (debug,info,warn,error,fatal)")
flag.BoolVar(&Config.ShowVersion, "version", ConfigYAML.ShowVersion, "Print version string")
flag.BoolVar(&Config.DeleteGauges, "delete-gauges", ConfigYAML.DeleteGauges, "Don't send values to graphite for inactive gauges, as opposed to sending the previous value")
flag.BoolVar(&Config.ResetCounters, "reset-counters", ConfigYAML.ResetCounters, "Reset counters after sending value to backend (send rate) or send cumulated value (artificial counter - eg. for OpenTSDB & Grafana)")
flag.Int64Var(&Config.PersistCountKeys, "persist-count-keys", ConfigYAML.PersistCountKeys, "Number of flush-intervals to persist count keys")
flag.StringVar(&Config.StatsPrefix, "stats-prefix", ConfigYAML.StatsPrefix, "Name for internal application metrics (no prefix prepended)")
flag.StringVar(&Config.StoreDb, "store-db", ConfigYAML.StoreDb, "Name of database for permanent counters storage (for conversion from rate to counter)")
flag.StringVar(&Config.Prefix, "prefix", ConfigYAML.Prefix, "Prefix for all stats")
flag.StringVar(&Config.ExtraTags, "extra-tags", ConfigYAML.ExtraTags, "Default tags added to all measures in format: tag1=value1 tag2=value2")
flag.Var(&Config.PercentThreshold, "percent-threshold", "Percentile calculation for timers (0-100, may be given multiple times)")
flag.BoolVar(&Config.PrintConfig, "print-config", ConfigYAML.PrintConfig, "Print config in YAML format")
flag.StringVar(&Config.LogName, "log-name", ConfigYAML.LogName, "Name of file to log into. If \"stdout\" than logs to stdout.If empty logs go to /dev/null")
flag.BoolVar(&Config.LogToSyslog, "log-to-syslopg", ConfigYAML.LogToSyslog, "Log to syslog")
flag.StringVar(&Config.SyslogUDPAddress, "syslog-udp-address", ConfigYAML.SyslogUDPAddress, "Syslog address with port number eg. localhost:514. If empty log to unix socket")
if parse {
flag.Parse()
}
if len(*configFile) > 0 {
if _, err = os.Stat(*configFile); os.IsNotExist(err) {
fmt.Printf("# Warning: No config file: %s\n", *configFile)
*configFile = ""
}
if len(*configFile) > 0 {
err = configor.Load(&ConfigYAML, *configFile)
if err != nil {
fmt.Printf("Error loading config file: %s\n", err)
} else {
// set configs read form YAML file
// save 2 flags
tmpConfig := Config
// Overwites flags
Config = ConfigYAML
// restore 2 flags
Config.ShowVersion = tmpConfig.ShowVersion
Config.PrintConfig = tmpConfig.PrintConfig
}
}
// visitor := func(a *flag.Flag) {
// fmt.Println(">", a.Name, "value=", a.Value)
// switch a.Name {
// case "print-config", "version":
// break
// case "udp-addr":
// ConfigYAML.UDPServiceAddress = a.Value.(string)
// default:
// fmt.Printf("Internal Config Error - unknown variable: %s\n", a.Name)
// os.Exit(1)
// }
//
// }
// flag.Visit(visitor)
}
// Normalize prefix
Config.Prefix = normalizeDot(Config.Prefix, true)
//.........這裏部分代碼省略.........