本文整理汇总了Golang中github.com/bitly/nsq/nsq.IsValidChannelName函数的典型用法代码示例。如果您正苦于以下问题:Golang IsValidChannelName函数的具体用法?Golang IsValidChannelName怎么用?Golang IsValidChannelName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsValidChannelName函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestChannelTopicNames
// test channel/topic names
func TestChannelTopicNames(t *testing.T) {
assert.Equal(t, nsq.IsValidChannelName("test"), true)
assert.Equal(t, nsq.IsValidChannelName("test-with_period."), true)
assert.Equal(t, nsq.IsValidChannelName("test#ephemeral"), true)
assert.Equal(t, nsq.IsValidTopicName("test"), true)
assert.Equal(t, nsq.IsValidTopicName("test-with_period."), true)
assert.Equal(t, nsq.IsValidTopicName("test#ephemeral"), false)
assert.Equal(t, nsq.IsValidTopicName("test:ephemeral"), false)
}
开发者ID:datastream,项目名称:nsq,代码行数:10,代码来源:protocol_v2_test.go
示例2: getTopicChan
func getTopicChan(command string, params []string) (string, string, error) {
if len(params) == 0 {
return "", "", nsq.NewFatalClientErr(nil, "E_INVALID", fmt.Sprintf("%s insufficient number of params", command))
}
topicName := params[0]
var channelName string
if len(params) >= 2 {
channelName = params[1]
}
if !nsq.IsValidTopicName(topicName) {
return "", "", nsq.NewFatalClientErr(nil, "E_BAD_TOPIC", fmt.Sprintf("%s topic name '%s' is not valid", command, topicName))
}
if channelName != "" && !nsq.IsValidChannelName(channelName) {
return "", "", nsq.NewFatalClientErr(nil, "E_BAD_CHANNEL", fmt.Sprintf("%s channel name '%s' is not valid", command, channelName))
}
return topicName, channelName, nil
}
开发者ID:datastream,项目名称:nsq,代码行数:21,代码来源:lookup_protocol_v1.go
示例3: GetTopicChannelArgs
func GetTopicChannelArgs(rp Getter) (string, string, error) {
topicName, err := rp.Get("topic")
if err != nil {
return "", "", errors.New("MISSING_ARG_TOPIC")
}
if !nsq.IsValidTopicName(topicName) {
return "", "", errors.New("INVALID_ARG_TOPIC")
}
channelName, err := rp.Get("channel")
if err != nil {
return "", "", errors.New("MISSING_ARG_CHANNEL")
}
if !nsq.IsValidChannelName(channelName) {
return "", "", errors.New("INVALID_ARG_CHANNEL")
}
return topicName, channelName, nil
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:21,代码来源:topic_channel_args.go
示例4: SUB
func (p *ProtocolV2) SUB(client *ClientV2, params [][]byte) ([]byte, error) {
if atomic.LoadInt32(&client.State) != nsq.StateInit {
return nil, nsq.NewFatalClientErr(nil, "E_INVALID", "cannot SUB in current state")
}
if client.HeartbeatInterval < 0 {
return nil, nsq.NewFatalClientErr(nil, "E_INVALID", "cannot SUB with heartbeats disabled")
}
if len(params) < 3 {
return nil, nsq.NewFatalClientErr(nil, "E_INVALID", "SUB insufficient number of parameters")
}
topicName := string(params[1])
if !nsq.IsValidTopicName(topicName) {
return nil, nsq.NewFatalClientErr(nil, "E_BAD_TOPIC",
fmt.Sprintf("SUB topic name '%s' is not valid", topicName))
}
channelName := string(params[2])
if !nsq.IsValidChannelName(channelName) {
return nil, nsq.NewFatalClientErr(nil, "E_BAD_CHANNEL",
fmt.Sprintf("SUB channel name '%s' is not valid", channelName))
}
topic := nsqd.GetTopic(topicName)
channel := topic.GetChannel(channelName)
channel.AddClient(client)
atomic.StoreInt32(&client.State, nsq.StateSubscribed)
client.Channel = channel
// update message pump
client.SubEventChan <- channel
return okBytes, nil
}
开发者ID:syshack,项目名称:nsq,代码行数:36,代码来源:protocol_v2.go
示例5: createTopicChannelHandler
func createTopicChannelHandler(w http.ResponseWriter, req *http.Request) {
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}
topicName, err := reqParams.Get("topic")
if err != nil || !nsq.IsValidTopicName(topicName) {
http.Error(w, "INVALID_TOPIC", 500)
return
}
channelName, err := reqParams.Get("channel")
if err != nil || (len(channelName) > 0 && !nsq.IsValidChannelName(channelName)) {
http.Error(w, "INVALID_CHANNEL", 500)
return
}
for _, addr := range lookupdHTTPAddrs {
endpoint := fmt.Sprintf("http://%s/create_topic?topic=%s", addr, url.QueryEscape(topicName))
log.Printf("LOOKUPD: querying %s", endpoint)
_, err := nsq.ApiRequest(endpoint)
if err != nil {
log.Printf("ERROR: lookupd %s - %s", endpoint, err.Error())
continue
}
}
NotifyAdminAction("create_topic", topicName, "", req)
if len(channelName) > 0 {
for _, addr := range lookupdHTTPAddrs {
endpoint := fmt.Sprintf("http://%s/create_channel?topic=%s&channel=%s",
addr, url.QueryEscape(topicName), url.QueryEscape(channelName))
log.Printf("LOOKUPD: querying %s", endpoint)
_, err := nsq.ApiRequest(endpoint)
if err != nil {
log.Printf("ERROR: lookupd %s - %s", endpoint, err.Error())
continue
}
}
// TODO: we can remove this when we push new channel information from nsqlookupd -> nsqd
producers, _ := getLookupdTopicProducers(topicName, lookupdHTTPAddrs)
for _, addr := range producers {
endpoint := fmt.Sprintf("http://%s/create_channel?topic=%s&channel=%s",
addr, url.QueryEscape(topicName), url.QueryEscape(channelName))
log.Printf("NSQD: querying %s", endpoint)
_, err := nsq.ApiRequest(endpoint)
if err != nil {
log.Printf("ERROR: nsqd %s - %s", endpoint, err.Error())
continue
}
}
NotifyAdminAction("create_channel", topicName, channelName, req)
}
http.Redirect(w, req, "/lookup", 302)
}
开发者ID:jmanero,项目名称:nsq,代码行数:61,代码来源:http.go
示例6: topicHandler
func topicHandler(w http.ResponseWriter, req *http.Request) {
var urlRegex = regexp.MustCompile(`^/topic/(.*)$`)
matches := urlRegex.FindStringSubmatch(req.URL.Path)
if len(matches) == 0 {
http.Error(w, "INVALID_TOPIC", 500)
return
}
parts := strings.Split(matches[1], "/")
topicName := parts[0]
if !nsq.IsValidTopicName(topicName) {
http.Error(w, "INVALID_TOPIC", 500)
return
}
if len(parts) == 2 {
channelName := parts[1]
if !nsq.IsValidChannelName(channelName) {
http.Error(w, "INVALID_CHANNEL", 500)
} else {
channelHandler(w, req, topicName, channelName)
}
return
}
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
http.Error(w, "INVALID_REQUEST", 500)
return
}
var producers []string
if len(lookupdHTTPAddrs) != 0 {
producers, _ = getLookupdTopicProducers(topicName, lookupdHTTPAddrs)
} else {
producers, _ = getNSQDTopicProducers(topicName, nsqdHTTPAddrs)
}
topicHostStats, channelStats, _ := getNSQDStats(producers, topicName)
globalTopicStats := &TopicHostStats{HostAddress: "Total"}
for _, t := range topicHostStats {
globalTopicStats.AddHostStats(t)
}
p := struct {
Title string
GraphOptions *GraphOptions
Version string
Topic string
TopicProducers []string
TopicHostStats []*TopicHostStats
GlobalTopicStats *TopicHostStats
ChannelStats map[string]*ChannelStats
}{
Title: fmt.Sprintf("NSQ %s", topicName),
GraphOptions: NewGraphOptions(w, req, reqParams),
Version: util.BINARY_VERSION,
Topic: topicName,
TopicProducers: producers,
TopicHostStats: topicHostStats,
GlobalTopicStats: globalTopicStats,
ChannelStats: channelStats,
}
err = templates.ExecuteTemplate(w, "topic.html", p)
if err != nil {
log.Printf("Template Error %s", err.Error())
http.Error(w, "Template Error", 500)
}
}
开发者ID:jmanero,项目名称:nsq,代码行数:68,代码来源:http.go
示例7: LoadMetadata
func (n *NSQd) LoadMetadata() {
fn := fmt.Sprintf(path.Join(n.options.dataPath, "nsqd.%d.dat"), n.workerId)
data, err := ioutil.ReadFile(fn)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("ERROR: failed to read channel metadata from %s - %s", fn, err.Error())
}
return
}
js, err := simplejson.NewJson(data)
if err != nil {
log.Printf("ERROR: failed to parse metadata - %s", err.Error())
return
}
topics, err := js.Get("topics").Array()
if err != nil {
log.Printf("ERROR: failed to parse metadata - %s", err.Error())
return
}
for ti := range topics {
topicJs := js.Get("topics").GetIndex(ti)
topicName, err := topicJs.Get("name").String()
if err != nil {
log.Printf("ERROR: failed to parse metadata - %s", err.Error())
return
}
if !nsq.IsValidTopicName(topicName) {
log.Printf("WARNING: skipping creation of invalid topic %s", topicName)
continue
}
topic := n.GetTopic(topicName)
channels, err := topicJs.Get("channels").Array()
if err != nil {
log.Printf("ERROR: failed to parse metadata - %s", err.Error())
return
}
for ci := range channels {
channelJs := topicJs.Get("channels").GetIndex(ci)
channelName, err := channelJs.Get("name").String()
if err != nil {
log.Printf("ERROR: failed to parse metadata - %s", err.Error())
return
}
if !nsq.IsValidChannelName(channelName) {
log.Printf("WARNING: skipping creation of invalid channel %s", channelName)
continue
}
channel := topic.GetChannel(channelName)
paused, _ := channelJs.Get("paused").Bool()
if paused {
channel.Pause()
}
}
}
}
开发者ID:newsky,项目名称:nsq,代码行数:63,代码来源:nsqd.go
注:本文中的github.com/bitly/nsq/nsq.IsValidChannelName函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论