源码

PS:这篇的目的是熟悉nsq的配置参数顺带说一下命令行解析


func nsqdFlagSet(opts *nsqd.Options) *flag.FlagSet {flagSet := flag.NewFlagSet("nsqd", flag.ExitOnError)//返回一个带有错误处理的  空的flag set。// basic optionsflagSet.Bool("version", false, "print version string")//以下类似的函数都是 name,+ 默认value + 说明的形式flagSet.String("config", "", "path to config file")logLevel := opts.LogLevelflagSet.Var(&logLevel, "log-level", "set log verbosity: debug, info, warn, error, or fatal")flagSet.String("log-prefix", "[nsqd] ", "log message prefix")flagSet.Bool("verbose", false, "[deprecated] has no effect, use --log-level")flagSet.Int64("node-id", opts.ID, "unique part for message IDs, (int) in range [0,1024) (default is hash of hostname)")flagSet.Bool("worker-id", false, "[deprecated] use --node-id")flagSet.String("https-address", opts.HTTPSAddress, "<addr>:<port> to listen on for HTTPS clients")flagSet.String("http-address", opts.HTTPAddress, "<addr>:<port> to listen on for HTTP clients")flagSet.String("tcp-address", opts.TCPAddress, "<addr>:<port> to listen on for TCP clients")authHTTPAddresses := app.StringArray{}flagSet.Var(&authHTTPAddresses, "auth-http-address", "<addr>:<port> to query auth server (may be given multiple times)")flagSet.String("broadcast-address", opts.BroadcastAddress, "address that will be registered with lookupd (defaults to the OS hostname)")lookupdTCPAddrs := app.StringArray{}flagSet.Var(&lookupdTCPAddrs, "lookupd-tcp-address", "lookupd TCP address (may be given multiple times)")flagSet.Duration("http-client-connect-timeout", opts.HTTPClientConnectTimeout, "timeout for HTTP connect")flagSet.Duration("http-client-request-timeout", opts.HTTPClientRequestTimeout, "timeout for HTTP request")// diskqueue optionsflagSet.String("data-path", opts.DataPath, "path to store disk-backed messages")flagSet.Int64("mem-queue-size", opts.MemQueueSize, "number of messages to keep in memory (per topic/channel)")flagSet.Int64("max-bytes-per-file", opts.MaxBytesPerFile, "number of bytes per diskqueue file before rolling")flagSet.Int64("sync-every", opts.SyncEvery, "number of messages per diskqueue fsync")flagSet.Duration("sync-timeout", opts.SyncTimeout, "duration of time per diskqueue fsync")flagSet.Int("queue-scan-worker-pool-max", opts.QueueScanWorkerPoolMax, "max concurrency for checking in-flight and deferred message timeouts")flagSet.Int("queue-scan-selection-count", opts.QueueScanSelectionCount, "number of channels to check per cycle (every 100ms) for in-flight and deferred timeouts")// msg and command optionsflagSet.Duration("msg-timeout", opts.MsgTimeout, "default duration to wait before auto-requeing a message")flagSet.Duration("max-msg-timeout", opts.MaxMsgTimeout, "maximum duration before a message will timeout")flagSet.Int64("max-msg-size", opts.MaxMsgSize, "maximum size of a single message in bytes")flagSet.Duration("max-req-timeout", opts.MaxReqTimeout, "maximum requeuing timeout for a message")flagSet.Int64("max-body-size", opts.MaxBodySize, "maximum size of a single command body")// client overridable configuration optionsflagSet.Duration("max-heartbeat-interval", opts.MaxHeartbeatInterval, "maximum client configurable duration of time between client heartbeats")flagSet.Int64("max-rdy-count", opts.MaxRdyCount, "maximum RDY count for a client")flagSet.Int64("max-output-buffer-size", opts.MaxOutputBufferSize, "maximum client configurable size (in bytes) for a client output buffer")flagSet.Duration("max-output-buffer-timeout", opts.MaxOutputBufferTimeout, "maximum client configurable duration of time between flushing to a client")flagSet.Duration("min-output-buffer-timeout", opts.MinOutputBufferTimeout, "minimum client configurable duration of time between flushing to a client")flagSet.Duration("output-buffer-timeout", opts.OutputBufferTimeout, "default duration of time between flushing data to clients")flagSet.Int("max-channel-consumers", opts.MaxChannelConsumers, "maximum channel consumer connection count per nsqd instance (default 0, i.e., unlimited)")// statsd integration optionsflagSet.String("statsd-address", opts.StatsdAddress, "UDP <addr>:<port> of a statsd daemon for pushing stats")flagSet.Duration("statsd-interval", opts.StatsdInterval, "duration between pushing to statsd")flagSet.Bool("statsd-mem-stats", opts.StatsdMemStats, "toggle sending memory and GC stats to statsd")flagSet.String("statsd-prefix", opts.StatsdPrefix, "prefix used for keys sent to statsd (%s for host replacement)")flagSet.Int("statsd-udp-packet-size", opts.StatsdUDPPacketSize, "the size in bytes of statsd UDP packets")// End to end percentile flagse2eProcessingLatencyPercentiles := app.FloatArray{}flagSet.Var(&e2eProcessingLatencyPercentiles, "e2e-processing-latency-percentile", "message processing time percentiles (as float (0, 1.0]) to track (can be specified multiple times or comma separated '1.0,0.99,0.95', default none)")flagSet.Duration("e2e-processing-latency-window-time", opts.E2EProcessingLatencyWindowTime, "calculate end to end latency quantiles for this duration of time (ie: 60s would only show quantile calculations from the past 60 seconds)")// TLS configflagSet.String("tls-cert", opts.TLSCert, "path to certificate file")flagSet.String("tls-key", opts.TLSKey, "path to key file")flagSet.String("tls-client-auth-policy", opts.TLSClientAuthPolicy, "client certificate auth policy ('require' or 'require-verify')")flagSet.String("tls-root-ca-file", opts.TLSRootCAFile, "path to certificate authority file")tlsRequired := tlsRequiredOption(opts.TLSRequired)tlsMinVersion := tlsMinVersionOption(opts.TLSMinVersion)flagSet.Var(&tlsRequired, "tls-required", "require TLS for client connections (true, false, tcp-https)")flagSet.Var(&tlsMinVersion, "tls-min-version", "minimum SSL/TLS version acceptable ('ssl3.0', 'tls1.0', 'tls1.1', or 'tls1.2')")// compressionflagSet.Bool("deflate", opts.DeflateEnabled, "enable deflate feature negotiation (client compression)")flagSet.Int("max-deflate-level", opts.MaxDeflateLevel, "max deflate compression level a client can negotiate (> values == > nsqd CPU usage)")flagSet.Bool("snappy", opts.SnappyEnabled, "enable snappy feature negotiation (client compression)")return flagSet
}

使用方式

flagSet := nsqdFlagSet(opts)
flagSet.Parse(os.Args[1:])//传入命令行参数
flagSet.Lookup("version").Value.(flag.Getter).Get().(bool)//读取version 参数的值。
func (f *FlagSet) Lookup(name string) *Flag
type Flag struct {Name     string // name as it appears on command lineUsage    string // help messageValue    Value  // value as setDefValue string // default value (as text); for usage message
}
type Getter interface {ValueGet() interface{}
}

整个为链式调用,lookup.Value 类型转换为flag.Getter通过Get接口拿到interface进行类型转换。

configFile := flagSet.Lookup("config").Value.String()

nsq命令行参数解析相关推荐

  1. 【Qt】通过QtCreator源码学习Qt(六):命令行参数解析实现

    参考下大神的命令行参数解析是如何是实现的 //使用const char []代替宏定义字符串,我以前都是用const QString,想想好傻 const char SETTINGS_OPTION[] ...

  2. python命令行参数解析OptionParser类用法实例

    python命令行参数解析OptionParser类用法实例 本文实例讲述了python命令行参数解析OptionParser类的用法,分享给大家供大家参考. 具体代码如下:     from opt ...

  3. 3gpp文件头文件解析_居于LLVM 的命令行参数解析

    在写命令行程序的时候经常需要解析各种命令行参数.打印help信息等,觉得非常的麻烦.今天介绍一种超级棒的命令参数解析的方法:居于LLVM 的命令行参数解析,有了它妈妈再也不用担心我不会解析命令行参数^ ...

  4. Python命令行参数解析模块------argparse

      首先,argparse 是python自带的命令行参数解析包,可以用来方便地读取命令行参数,当你的代码需要频繁地修改参数的时候,使用这个工具可以将参数和代码分离开来,让你的代码更简洁,适用范围更广 ...

  5. 编程模板-R语言脚本写作:最简单的统计与绘图,包安装、命令行参数解析、文件读取、表格和矢量图输出

    写在前面 个人认为:是否能熟悉使用Shell(项目流程搭建)+R(数据统计与可视化)+Perl/Python等(胶水语言,数据格式转换,软件间衔接)三门语言是一位合格生物信息工程师的标准. 之前分享过 ...

  6. Python中最好用的命令行参数解析工具

    Python 做为一个脚本语言,可以很方便地写各种工具.当你在服务端要运行一个工具或服务时,输入参数似乎是一种硬需(当然你也可以通过配置文件来实现). 如果要以命令行执行,那你需要解析一个命令行参数解 ...

  7. python 命令行参数-Python 中最好用的命令行参数解析工具

    Python 做为一个脚本语言,可以很方便地写各种工具.当你在服务端要运行一个工具或服务时,输入参数似乎是一种硬需(当然你也可以通过配置文件来实现). 如果要以命令行执行,那你需要一个命令行参数解析的 ...

  8. linux shell中的命令自动补全(compgen complete)与 命令行参数解析

    linux shell中的命令自动补全(compgen complete)与 命令行参数解析 标签: shell脚本 2013-12-31 21:56 6661人阅读 评论(6) 收藏 举报 分类: ...

  9. GO标准库—命令行参数解析FLAG

    评论有人提到没有例子,不知道讲的是什么.因此,为了大家能够更好地理解,特意加了一个示例.其实本文更多讲解的是 flag 的实现原理,加上示例之后,就更好地知道怎么使用了.建议阅读 <Go语言标准 ...

最新文章

  1. 【Spring】通过动态代理改进银行转账事务控制
  2. KDD2020接受论文列表已公开!338篇优秀论文汇总!
  3. 关于Puppet不得不说的故事
  4. MSI failed, 不能卸载VMware
  5. COMBOBOX绑定DICTIONARY做为数据源
  6. 不能将参数转化为lparam_反渗透纯水机是将自来水直接转化为超纯水的装置
  7. (三)用docker-compose部署postgres+ postgis
  8. Junit 与 powermock 结合执行过程源码阅读
  9. java socket如何请求485协议_javaSE第十五部分 网络编程(1)Socket和ServerSocket
  10. (转)RabbitMQ学习之主题topic(java)
  11. Citrix高层相继离职,XenServer或将被流产?
  12. JDK绘制文字的流程与代码分析
  13. 麦本本笔记本怎么U盘重装Win10系统教学?
  14. 国内互联网大数据的发展现状和应用
  15. 什么是Memcached?
  16. 水星怎么设置网速最快_水星路由器怎么限制别人网速_水星怎么限制wifi网速?-192路由网...
  17. ppt怎么转换为pdf
  18. KISSY基础篇乄KISSY之IO(2)
  19. MSRA显著性检测数据集
  20. 顺丰下单空运实际发陆运

热门文章

  1. Linux下使用readline库实现2048游戏
  2. 写代码必备2K超清可旋转显示器,把乔哥腰包榨干!
  3. 立体匹配研究背景及意义
  4. opengl鼠标点击选取模型
  5. 蓝牙耳机哪个牌子好?蓝牙耳机品牌推荐
  6. 游戏行业首批“版号解冻” 但腾讯网易旗下产品暂不在列
  7. js正则表达式之中文验证(转)
  8. Android之设备ID(Device ID)
  9. lua服务执行过程中协程的挂起和重新唤醒
  10. 倒计时进度条动态效果