本文整理汇总了Golang中github.com/bitly/nsq/internal/version.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flagSet.Parse(os.Args[1:])
if *showVersion {
fmt.Println(version.String("nsqlookupd"))
return
}
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
var cfg map[string]interface{}
if *config != "" {
_, err := toml.DecodeFile(*config, &cfg)
if err != nil {
log.Fatalf("ERROR: failed to load config file %s - %s", *config, err.Error())
}
}
opts := nsqlookupd.NewOptions()
options.Resolve(opts, flagSet, cfg)
daemon := nsqlookupd.New(opts)
daemon.Main()
<-signalChan
daemon.Exit()
}
开发者ID:rpau,项目名称:nsq,代码行数:27,代码来源:nsqlookupd.go
示例2: New
func New(opts *Options) *NSQLookupd {
n := &NSQLookupd{
opts: opts,
DB: NewRegistrationDB(),
}
n.logf(version.String("nsqlookupd"))
return n
}
开发者ID:rpau,项目名称:nsq,代码行数:8,代码来源:nsqlookupd.go
示例3: New
func New(opts *Options) *NSQD {
n := &NSQD{
flag: flagHealthy,
startTime: time.Now(),
topicMap: make(map[string]*Topic),
idChan: make(chan MessageID, 4096),
exitChan: make(chan int),
notifyChan: make(chan interface{}),
optsNotificationChan: make(chan struct{}, 1),
ci: clusterinfo.New(opts.Logger, http_api.NewClient(nil)),
}
n.swapOpts(opts)
if opts.MaxDeflateLevel < 1 || opts.MaxDeflateLevel > 9 {
n.logf("FATAL: --max-deflate-level must be [1,9]")
os.Exit(1)
}
if opts.ID < 0 || opts.ID >= 1024 {
n.logf("FATAL: --worker-id must be [0,1024)")
os.Exit(1)
}
if opts.StatsdPrefix != "" {
_, port, err := net.SplitHostPort(opts.HTTPAddress)
if err != nil {
n.logf("ERROR: failed to parse HTTP address (%s) - %s", opts.HTTPAddress, err)
os.Exit(1)
}
statsdHostKey := statsd.HostKey(net.JoinHostPort(opts.BroadcastAddress, port))
prefixWithHost := strings.Replace(opts.StatsdPrefix, "%s", statsdHostKey, -1)
if prefixWithHost[len(prefixWithHost)-1] != '.' {
prefixWithHost += "."
}
opts.StatsdPrefix = prefixWithHost
}
if opts.TLSClientAuthPolicy != "" && opts.TLSRequired == TLSNotRequired {
opts.TLSRequired = TLSRequired
}
tlsConfig, err := buildTLSConfig(opts)
if err != nil {
n.logf("FATAL: failed to build TLS config - %s", err)
os.Exit(1)
}
if tlsConfig == nil && opts.TLSRequired != TLSNotRequired {
n.logf("FATAL: cannot require TLS client connections without TLS key and cert")
os.Exit(1)
}
n.tlsConfig = tlsConfig
n.logf(version.String("nsqd"))
n.logf("ID: %d", opts.ID)
return n
}
开发者ID:michaeltrobinson,项目名称:nsq,代码行数:57,代码来源:nsqd.go
示例4: NewNSQAdmin
func NewNSQAdmin(opts *nsqadminOptions) *NSQAdmin {
n := &NSQAdmin{
opts: opts,
notifications: make(chan *AdminAction),
}
if len(opts.NSQDHTTPAddresses) == 0 && len(opts.NSQLookupdHTTPAddresses) == 0 {
n.logf("--nsqd-http-address or --lookupd-http-address required.")
os.Exit(1)
}
if len(opts.NSQDHTTPAddresses) != 0 && len(opts.NSQLookupdHTTPAddresses) != 0 {
n.logf("use --nsqd-http-address or --lookupd-http-address not both")
os.Exit(1)
}
// verify that the supplied address is valid
verifyAddress := func(arg string, address string) *net.TCPAddr {
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
n.logf("FATAL: failed to resolve %s address (%s) - %s", arg, address, err)
os.Exit(1)
}
return addr
}
// require that both the hostname and port be specified
for _, address := range opts.NSQLookupdHTTPAddresses {
verifyAddress("--lookupd-http-address", address)
}
for _, address := range opts.NSQDHTTPAddresses {
verifyAddress("--nsqd-http-address", address)
}
if opts.ProxyGraphite {
url, err := url.Parse(opts.GraphiteURL)
if err != nil {
n.logf("FATAL: failed to parse --graphite-url='%s' - %s", opts.GraphiteURL, err)
os.Exit(1)
}
n.graphiteURL = url
}
n.logf(version.String("nsqadmin"))
return n
}
开发者ID:zhangyuchen0411,项目名称:nsq,代码行数:48,代码来源:nsqadmin.go
示例5: main
func main() {
flagSet := nsqFlagset()
flagSet.Parse(os.Args[1:])
rand.Seed(time.Now().UTC().UnixNano())
if flagSet.Lookup("version").Value.(flag.Getter).Get().(bool) {
fmt.Println(version.String("nsqd"))
return
}
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
var cfg config
configFile := flagSet.Lookup("config").Value.String()
if configFile != "" {
_, err := toml.DecodeFile(configFile, &cfg)
if err != nil {
log.Fatalf("ERROR: failed to load config file %s - %s", configFile, err.Error())
}
}
cfg.Validate()
opts := nsqd.NewOptions()
options.Resolve(opts, flagSet, cfg)
nsqd := nsqd.New(opts)
nsqd.LoadMetadata()
err := nsqd.PersistMetadata()
if err != nil {
log.Fatalf("ERROR: failed to persist metadata - %s", err.Error())
}
nsqd.Main()
<-signalChan
nsqd.Exit()
}
开发者ID:jungle0755,项目名称:nsq,代码行数:38,代码来源:nsqd.go
示例6: NewNSQLookupd
func NewNSQLookupd(opts *nsqlookupdOptions) *NSQLookupd {
n := &NSQLookupd{
opts: opts,
DB: NewRegistrationDB(),
}
tcpAddr, err := net.ResolveTCPAddr("tcp", opts.TCPAddress)
if err != nil {
n.logf("FATAL: failed to resolve TCP address (%s) - %s", opts.TCPAddress, err)
os.Exit(1)
}
n.tcpAddr = tcpAddr
httpAddr, err := net.ResolveTCPAddr("tcp", opts.HTTPAddress)
if err != nil {
n.logf("FATAL: failed to resolve HTTP address (%s) - %s", opts.HTTPAddress, err)
os.Exit(1)
}
n.httpAddr = httpAddr
n.logf(version.String("nsqlookupd"))
return n
}
开发者ID:judwhite,项目名称:nsq-0.3.2-win,代码行数:24,代码来源:nsqlookupd.go
示例7: main
func main() {
flagSet.Parse(os.Args[1:])
if *showVersion {
fmt.Println(version.String("nsqadmin"))
return
}
if *templateDir != "" {
log.Printf("WARNING: --template-dir is deprecated and will be removed in the next release (templates are now compiled into the binary)")
}
exitChan := make(chan int)
signalChan := make(chan os.Signal, 1)
go func() {
<-signalChan
exitChan <- 1
}()
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
var cfg map[string]interface{}
if *config != "" {
_, err := toml.DecodeFile(*config, &cfg)
if err != nil {
log.Fatalf("ERROR: failed to load config file %s - %s", *config, err)
}
}
opts := nsqadmin.NewNSQAdminOptions()
options.Resolve(opts, flagSet, cfg)
nsqadmin := nsqadmin.NewNSQAdmin(opts)
nsqadmin.Main()
<-exitChan
nsqadmin.Exit()
}
开发者ID:zhangyuchen0411,项目名称:nsq,代码行数:36,代码来源:main.go
示例8: printStats
func (s *httpServer) printStats(stats []TopicStats, health string, startTime time.Time, uptime time.Duration) []byte {
var buf bytes.Buffer
w := &buf
now := time.Now()
io.WriteString(w, fmt.Sprintf("%s\n", version.String("nsqd")))
io.WriteString(w, fmt.Sprintf("start_time %v\n", startTime.Format(time.RFC3339)))
io.WriteString(w, fmt.Sprintf("uptime %s\n", uptime))
if len(stats) == 0 {
io.WriteString(w, "\nNO_TOPICS\n")
return buf.Bytes()
}
io.WriteString(w, fmt.Sprintf("\nHealth: %s\n", health))
for _, t := range stats {
var pausedPrefix string
if t.Paused {
pausedPrefix = "*P "
} else {
pausedPrefix = " "
}
io.WriteString(w, fmt.Sprintf("\n%s[%-15s] depth: %-5d be-depth: %-5d msgs: %-8d e2e%%: %s\n",
pausedPrefix,
t.TopicName,
t.Depth,
t.BackendDepth,
t.MessageCount,
t.E2eProcessingLatency))
for _, c := range t.Channels {
if c.Paused {
pausedPrefix = " *P "
} else {
pausedPrefix = " "
}
io.WriteString(w,
fmt.Sprintf("%s[%-25s] depth: %-5d be-depth: %-5d inflt: %-4d def: %-4d re-q: %-5d timeout: %-5d msgs: %-8d e2e%%: %s\n",
pausedPrefix,
c.ChannelName,
c.Depth,
c.BackendDepth,
c.InFlightCount,
c.DeferredCount,
c.RequeueCount,
c.TimeoutCount,
c.MessageCount,
c.E2eProcessingLatency))
for _, client := range c.Clients {
connectTime := time.Unix(client.ConnectTime, 0)
// truncate to the second
duration := time.Duration(int64(now.Sub(connectTime).Seconds())) * time.Second
_, port, _ := net.SplitHostPort(client.RemoteAddress)
io.WriteString(w, fmt.Sprintf(" [%s %-21s] state: %d inflt: %-4d rdy: %-4d fin: %-8d re-q: %-8d msgs: %-8d connected: %s\n",
client.Version,
fmt.Sprintf("%s:%s", client.Name, port),
client.State,
client.InFlightCount,
client.ReadyCount,
client.FinishCount,
client.RequeueCount,
client.MessageCount,
duration,
))
}
}
}
return buf.Bytes()
}
开发者ID:rpau,项目名称:nsq,代码行数:65,代码来源:http.go
示例9: New
func New(opts *Options) *NSQAdmin {
n := &NSQAdmin{
opts: opts,
notifications: make(chan *AdminAction),
}
if len(opts.NSQDHTTPAddresses) == 0 && len(opts.NSQLookupdHTTPAddresses) == 0 {
n.logf("--nsqd-http-address or --lookupd-http-address required.")
os.Exit(1)
}
if len(opts.NSQDHTTPAddresses) != 0 && len(opts.NSQLookupdHTTPAddresses) != 0 {
n.logf("use --nsqd-http-address or --lookupd-http-address not both")
os.Exit(1)
}
// verify that the supplied address is valid
verifyAddress := func(arg string, address string) *net.TCPAddr {
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
n.logf("FATAL: failed to resolve %s address (%s) - %s", arg, address, err)
os.Exit(1)
}
return addr
}
if opts.HTTPClientTLSCert != "" && opts.HTTPClientTLSKey == "" {
n.logf("FATAL: --http-client-tls-key must be specified with --http-client-tls-cert")
os.Exit(1)
}
if opts.HTTPClientTLSKey != "" && opts.HTTPClientTLSCert == "" {
n.logf("FATAL: --http-client-tls-cert must be specified with --http-client-tls-key")
os.Exit(1)
}
n.httpClientTLSConfig = &tls.Config{
InsecureSkipVerify: opts.HTTPClientTLSInsecureSkipVerify,
}
if opts.HTTPClientTLSCert != "" && opts.HTTPClientTLSKey != "" {
cert, err := tls.LoadX509KeyPair(opts.HTTPClientTLSCert, opts.HTTPClientTLSKey)
if err != nil {
n.logf("FATAL: failed to LoadX509KeyPair %s, %s - %s",
opts.HTTPClientTLSCert, opts.HTTPClientTLSKey, err)
os.Exit(1)
}
n.httpClientTLSConfig.Certificates = []tls.Certificate{cert}
}
if opts.HTTPClientTLSRootCAFile != "" {
tlsCertPool := x509.NewCertPool()
caCertFile, err := ioutil.ReadFile(opts.HTTPClientTLSRootCAFile)
if err != nil {
n.logf("FATAL: failed to read TLS root CA file %s - %s",
opts.HTTPClientTLSRootCAFile, err)
os.Exit(1)
}
if !tlsCertPool.AppendCertsFromPEM(caCertFile) {
n.logf("FATAL: failed to AppendCertsFromPEM %s", opts.HTTPClientTLSRootCAFile)
os.Exit(1)
}
n.httpClientTLSConfig.ClientCAs = tlsCertPool
}
// require that both the hostname and port be specified
for _, address := range opts.NSQLookupdHTTPAddresses {
verifyAddress("--lookupd-http-address", address)
}
for _, address := range opts.NSQDHTTPAddresses {
verifyAddress("--nsqd-http-address", address)
}
if opts.ProxyGraphite {
url, err := url.Parse(opts.GraphiteURL)
if err != nil {
n.logf("FATAL: failed to parse --graphite-url='%s' - %s", opts.GraphiteURL, err)
os.Exit(1)
}
n.graphiteURL = url
}
n.logf(version.String("nsqadmin"))
return n
}
开发者ID:michaeltrobinson,项目名称:nsq,代码行数:85,代码来源:nsqadmin.go
注:本文中的github.com/bitly/nsq/internal/version.String函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论