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 對象:sql

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 提供了哪些方法:json

// 讀取 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() {}
本站公眾號
   歡迎關注本站公眾號,獲取更多信息