nsqadmin
nsqadmin 结构体定义
type Options struct {
LogLevel string `flag:"log-level"`
LogPrefix string `flag:"log-prefix"`
Verbose bool `flag:"verbose"` // for backwards compatibility
Logger Logger
logLevel lg.LogLevel // private, not really an option
HTTPAddress string `flag:"http-address"`
GraphiteURL string `flag:"graphite-url"`
ProxyGraphite bool `flag:"proxy-graphite"`
StatsdPrefix string `flag:"statsd-prefix"`
StatsdCounterFormat string `flag:"statsd-counter-format"`
StatsdGaugeFormat string `flag:"statsd-gauge-format"`
StatsdInterval time.Duration `flag:"statsd-interval"`
NSQLookupdHTTPAddresses []string `flag:"lookupd-http-address" cfg:"nsqlookupd_http_addresses"`
NSQDHTTPAddresses []string `flag:"nsqd-http-address" cfg:"nsqd_http_addresses"`
HTTPClientConnectTimeout time.Duration `flag:"http-client-connect-timeout"`
HTTPClientRequestTimeout time.Duration `flag:"http-client-request-timeout"`
HTTPClientTLSInsecureSkipVerify bool `flag:"http-client-tls-insecure-skip-verify"`
HTTPClientTLSRootCAFile string `flag:"http-client-tls-root-ca-file"`
HTTPClientTLSCert string `flag:"http-client-tls-cert"`
HTTPClientTLSKey string `flag:"http-client-tls-key"`
AllowConfigFromCIDR string `flag:"allow-config-from-cidr"`
NotificationHTTPEndpoint string `flag:"notification-http-endpoint"`
AclHttpHeader string `flag:"acl-http-header"`
AdminUsers []string `flag:"admin-user" cfg:"admin_users"`
}
Options 只有一个 New 方法, 就是创建一个 NSQAdmin 对象:
func New(opts *Options) *NSQAdmin {}
type NSQAdmin struct {
sync.RWMutex
opts atomic.Value // interface 类型,实际保存的是 *Options
httpListener net.Listener
waitGroup util.WaitGroupWrapper
notifications chan *AdminAction
graphiteURL *url.URL
httpClientTLSConfig *tls.Config
}
再看看 NSQAdmin 提供了哪些方法:
// 读取 ops 的值,这里用的 atomic 来保证同步操作
func (n *NSQAdmin) getOpts() *Options {}
// 存储 ops 的值
func (n *NSQAdmin) swapOpts(opts *Options) {}
// 返回服务器地址,即: net.Listener.Addr()
func (n *NSQAdmin) RealHTTPAddr() *net.TCPAddr {}
// 从 channel 中读取消息,转换成 json, 然后发送到 nsq 节点
func (n *NSQAdmin) handleAdminActions() {}
// 退出清理操作
// 关闭 http 监听, 关闭 channel
func (n *NSQAdmin) Exit() {}
// 监听端口
func (n *NSQAdmin) Main() {}