本文整理汇总了Golang中github.com/bitly/nsq/util.ApiResponse函数的典型用法代码示例。如果您正苦于以下问题:Golang ApiResponse函数的具体用法?Golang ApiResponse怎么用?Golang ApiResponse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ApiResponse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pauseChannelHandler
func (s *httpServer) pauseChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
util.ApiResponse(w, 500, err.Error(), nil)
return
}
topic, err := s.context.nsqd.GetExistingTopic(topicName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_TOPIC", nil)
return
}
channel, err := topic.GetExistingChannel(channelName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_CHANNEL", nil)
return
}
if strings.HasPrefix(req.URL.Path, "/pause") {
channel.Pause()
} else {
channel.UnPause()
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:michaelhood,项目名称:nsq,代码行数:34,代码来源:http.go
示例2: deleteChannelHandler
func (s *httpServer) deleteChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
util.ApiResponse(w, 500, err.Error(), nil)
return
}
topic, err := s.context.nsqd.GetExistingTopic(topicName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_TOPIC", nil)
return
}
err = topic.DeleteExistingChannel(channelName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_CHANNEL", nil)
return
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:michaelhood,项目名称:nsq,代码行数:28,代码来源:http.go
示例3: deleteTopicHandler
func deleteTopicHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
registrations := lookupd.DB.FindRegistrations("channel", topicName, "*")
for _, registration := range registrations {
log.Printf("DB: removing channel(%s) from topic(%s)", registration.SubKey, topicName)
lookupd.DB.RemoveRegistration(*registration)
}
registrations = lookupd.DB.FindRegistrations("topic", topicName, "")
for _, registration := range registrations {
log.Printf("DB: removing topic(%s)", topicName)
lookupd.DB.RemoveRegistration(*registration)
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:datastream,项目名称:nsq,代码行数:27,代码来源:http.go
示例4: putHandler
func putHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
if !nsq.IsValidTopicName(topicName) {
util.ApiResponse(w, 500, "INVALID_ARG_TOPIC", nil)
return
}
if int64(len(reqParams.Body)) > nsqd.options.maxMessageSize {
util.ApiResponse(w, 500, "MSG_TOO_BIG", nil)
return
}
topic := nsqd.GetTopic(topicName)
msg := nsq.NewMessage(<-nsqd.idChan, reqParams.Body)
err = topic.PutMessage(msg)
if err != nil {
util.ApiResponse(w, 500, "NOK", nil)
return
}
w.Header().Set("Content-Length", "2")
io.WriteString(w, "OK")
}
开发者ID:jmanero,项目名称:nsq,代码行数:35,代码来源:http.go
示例5: tombstoneTopicProducerHandler
func tombstoneTopicProducerHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
node, err := reqParams.Get("node")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_NODE", nil)
return
}
log.Printf("DB: setting tombstone for [email protected]%s of topic(%s)", node, topicName)
producers := lookupd.DB.FindProducers("topic", topicName, "")
for _, p := range producers {
thisNode := fmt.Sprintf("%s:%d", p.peerInfo.BroadcastAddress, p.peerInfo.HttpPort)
if thisNode == node {
p.Tombstone()
}
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:datastream,项目名称:nsq,代码行数:30,代码来源:http.go
示例6: pauseTopicHandler
func (s *httpServer) pauseTopicHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
topic, err := s.context.nsqd.GetExistingTopic(topicName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_TOPIC", nil)
return
}
if strings.HasPrefix(req.URL.Path, "/pause") {
err = topic.Pause()
} else {
err = topic.UnPause()
}
if err != nil {
log.Printf("ERROR: failure in %s - %s", req.URL.Path, err.Error())
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:jsocol,项目名称:nsq,代码行数:31,代码来源:http.go
示例7: deleteChannelHandler
func deleteChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
util.ApiResponse(w, 500, err.Error(), nil)
return
}
registrations := lookupd.DB.FindRegistrations("channel", topicName, channelName)
if len(registrations) == 0 {
util.ApiResponse(w, 404, "NOT_FOUND", nil)
return
}
log.Printf("DB: removing channel(%s) from topic(%s)", channelName, topicName)
for _, registration := range registrations {
lookupd.DB.RemoveRegistration(*registration)
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:datastream,项目名称:nsq,代码行数:26,代码来源:http.go
示例8: statsHandler
func (s *httpServer) statsHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err)
if acceptVersion(req) == 1 {
util.V1ApiResponse(w, 400, "INVALID_REQUEST")
} else {
// this handler always returns 500 for backwards compatibility
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
}
return
}
formatString, _ := reqParams.Get("format")
jsonFormat := formatString == "json"
stats := s.context.nsqd.GetStats()
if !jsonFormat {
s.doTextStats(stats, w)
return
}
if acceptVersion(req) == 1 {
util.V1ApiResponse(w, 200, struct {
Version string `json:"version"`
Topics []TopicStats `json:"topics"`
}{util.BINARY_VERSION, stats})
} else {
util.ApiResponse(w, 200, "OK", struct {
Version string `json:"version"`
Topics []TopicStats `json:"topics"`
}{util.BINARY_VERSION, stats})
}
}
开发者ID:pombredanne,项目名称:nsq,代码行数:33,代码来源:http.go
示例9: lookupHandler
func lookupHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
registration := lookupd.DB.FindRegistrations("topic", topicName, "")
if len(registration) == 0 {
util.ApiResponse(w, 500, "INVALID_ARG_TOPIC", nil)
return
}
channels := lookupd.DB.FindRegistrations("channel", topicName, "*").SubKeys()
producers := lookupd.DB.FindProducers("topic", topicName, "")
producers = producers.FilterByActive(lookupd.inactiveProducerTimeout, lookupd.tombstoneLifetime)
data := make(map[string]interface{})
data["channels"] = channels
data["producers"] = producers.PeerInfo()
util.ApiResponse(w, 200, "OK", data)
}
开发者ID:datastream,项目名称:nsq,代码行数:29,代码来源:http.go
示例10: counterDataHandler
// this endpoint works by giving out an ID that maps to a stats dictionary
// The initial request is the number of messages processed since each nsqd started up.
// Subsequent requsts pass that ID and get an updated delta based on each individual channel/nsqd message count
// That ID must be re-requested or it will be expired.
func (s *httpServer) counterDataHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
statsID, _ := reqParams.Get("id")
now := time.Now()
if statsID == "" {
// make a new one
statsID = fmt.Sprintf("%d.%d", now.Unix(), now.UnixNano())
}
stats, ok := s.counters[statsID]
if !ok {
stats = make(map[string]int64)
}
newStats := make(map[string]int64)
newStats["time"] = now.Unix()
producers, _ := lookupd.GetLookupdProducers(s.context.nsqadmin.options.NSQLookupdHTTPAddresses)
addresses := make([]string, len(producers))
for i, p := range producers {
addresses[i] = p.HTTPAddress()
}
_, channelStats, _ := lookupd.GetNSQDStats(addresses, "")
var newMessages int64
var totalMessages int64
for _, channelStats := range channelStats {
for _, hostChannelStats := range channelStats.HostStats {
key := fmt.Sprintf("%s:%s:%s", channelStats.TopicName, channelStats.ChannelName, hostChannelStats.HostAddress)
d, ok := stats[key]
if ok && d <= hostChannelStats.MessageCount {
newMessages += (hostChannelStats.MessageCount - d)
}
totalMessages += hostChannelStats.MessageCount
newStats[key] = hostChannelStats.MessageCount
}
}
s.counters[statsID] = newStats
data := make(map[string]interface{})
data["new_messages"] = newMessages
data["total_messages"] = totalMessages
data["id"] = statsID
util.ApiResponse(w, 200, "OK", data)
}
开发者ID:jsocol,项目名称:nsq,代码行数:54,代码来源:http.go
示例11: ServeHTTP
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/ping":
s.pingHandler(w, req)
case "/info":
s.infoHandler(w, req)
case "/lookup":
s.lookupHandler(w, req)
case "/topics":
s.topicsHandler(w, req)
case "/channels":
s.channelsHandler(w, req)
case "/nodes":
s.nodesHandler(w, req)
case "/delete_topic":
s.deleteTopicHandler(w, req)
case "/delete_channel":
s.deleteChannelHandler(w, req)
case "/tombstone_topic_producer":
s.tombstoneTopicProducerHandler(w, req)
case "/create_topic":
s.createTopicHandler(w, req)
case "/create_channel":
s.createChannelHandler(w, req)
case "/debug":
s.debugHandler(w, req)
default:
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}
开发者ID:newsky,项目名称:nsq,代码行数:30,代码来源:http.go
示例12: infoHandler
func infoHandler(w http.ResponseWriter, req *http.Request) {
util.ApiResponse(w, 200, "OK", struct {
Version string `json:"version"`
}{
Version: util.BINARY_VERSION,
})
}
开发者ID:datastream,项目名称:nsq,代码行数:7,代码来源:http.go
示例13: debugHandler
func debugHandler(w http.ResponseWriter, req *http.Request) {
lookupd.DB.RLock()
defer lookupd.DB.RUnlock()
data := make(map[string][]map[string]interface{})
for r, producers := range lookupd.DB.registrationMap {
key := r.Category + ":" + r.Key + ":" + r.SubKey
data[key] = make([]map[string]interface{}, 0)
for _, p := range producers {
m := make(map[string]interface{})
m["id"] = p.peerInfo.id
m["address"] = p.peerInfo.Address //TODO: remove for 1.0
m["hostname"] = p.peerInfo.Hostname
m["broadcast_address"] = p.peerInfo.BroadcastAddress
m["tcp_port"] = p.peerInfo.TcpPort
m["http_port"] = p.peerInfo.HttpPort
m["version"] = p.peerInfo.Version
m["last_update"] = p.peerInfo.lastUpdate.UnixNano()
m["tombstoned"] = p.tombstoned
m["tombstoned_at"] = p.tombstonedAt.UnixNano()
data[key] = append(data[key], m)
}
}
util.ApiResponse(w, 200, "OK", data)
}
开发者ID:datastream,项目名称:nsq,代码行数:26,代码来源:http.go
示例14: ServeHTTP
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
err := s.debugRouter(w, req)
if err != nil {
log.Printf("ERROR: %s", err)
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}
开发者ID:samuelyao314,项目名称:mygo,代码行数:7,代码来源:http.go
示例15: pauseChannelHandler
func (s *httpServer) pauseChannelHandler(w http.ResponseWriter, req *http.Request) {
err := s.doPauseChannel(req)
if err != nil {
if acceptVersion(req) == 1 {
util.V1ApiResponse(w, err.(httpError).Code(), err)
} else {
// this handler always returns 500 for backwards compatibility
util.ApiResponse(w, 500, err.Error(), nil)
}
return
}
if acceptVersion(req) == 1 {
util.V1ApiResponse(w, 200, nil)
} else {
util.ApiResponse(w, 200, "OK", nil)
}
}
开发者ID:pombredanne,项目名称:nsq,代码行数:17,代码来源:http.go
示例16: createTopicHandler
func (s *httpServer) createTopicHandler(w http.ResponseWriter, req *http.Request) {
_, _, err := s.getTopicFromQuery(req)
if err != nil {
if acceptVersion(req) == 1 {
util.V1ApiResponse(w, err.(httpError).Code(), err)
} else {
// this handler always returns 500 for backwards compatibility
util.ApiResponse(w, 500, err.Error(), nil)
}
return
}
if acceptVersion(req) == 1 {
util.V1ApiResponse(w, 200, nil)
} else {
util.ApiResponse(w, 200, "OK", nil)
}
}
开发者ID:pombredanne,项目名称:nsq,代码行数:17,代码来源:http.go
示例17: channelsHandler
func channelsHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
channels := lookupd.DB.FindRegistrations("channel", topicName, "*").SubKeys()
data := make(map[string]interface{})
data["channels"] = channels
util.ApiResponse(w, 200, "OK", data)
}
开发者ID:datastream,项目名称:nsq,代码行数:18,代码来源:http.go
示例18: ServeHTTP
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/pub":
fallthrough
case "/put":
s.putHandler(w, req)
case "/mpub":
fallthrough
case "/mput":
s.mputHandler(w, req)
case "/stats":
s.statsHandler(w, req)
case "/ping":
s.pingHandler(w, req)
case "/info":
s.infoHandler(w, req)
case "/empty_topic":
s.emptyTopicHandler(w, req)
case "/delete_topic":
s.deleteTopicHandler(w, req)
case "/pause_topic":
s.pauseTopicHandler(w, req)
case "/unpause_topic":
s.pauseTopicHandler(w, req)
case "/empty_channel":
s.emptyChannelHandler(w, req)
case "/delete_channel":
s.deleteChannelHandler(w, req)
case "/pause_channel":
s.pauseChannelHandler(w, req)
case "/unpause_channel":
s.pauseChannelHandler(w, req)
case "/create_topic":
s.createTopicHandler(w, req)
case "/create_channel":
s.createChannelHandler(w, req)
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/cmdline":
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
httpprof.Symbol(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/profile":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
log.Printf("ERROR: 404 %s", req.URL.Path)
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}
开发者ID:jsocol,项目名称:nsq,代码行数:57,代码来源:http.go
示例19: emptyChannelHandler
func emptyChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
util.ApiResponse(w, 500, err.Error(), nil)
return
}
topic, err := nsqd.GetExistingTopic(topicName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_TOPIC", nil)
return
}
channel, err := topic.GetExistingChannel(channelName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_CHANNEL", nil)
return
}
err = channel.Empty()
if err != nil {
util.ApiResponse(w, 500, "INTERNAL_ERROR", nil)
return
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:jmanero,项目名称:nsq,代码行数:34,代码来源:http.go
示例20: emptyTopicHandler
func (s *httpServer) emptyTopicHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
util.ApiResponse(w, 500, "INVALID_REQUEST", nil)
return
}
topicName, err := reqParams.Get("topic")
if err != nil {
util.ApiResponse(w, 500, "MISSING_ARG_TOPIC", nil)
return
}
if !nsq.IsValidTopicName(topicName) {
util.ApiResponse(w, 500, "INVALID_TOPIC", nil)
return
}
topic, err := s.context.nsqd.GetExistingTopic(topicName)
if err != nil {
util.ApiResponse(w, 500, "INVALID_TOPIC", nil)
return
}
err = topic.Empty()
if err != nil {
util.ApiResponse(w, 500, "INTERNAL_ERROR", nil)
return
}
util.ApiResponse(w, 200, "OK", nil)
}
开发者ID:michaelhood,项目名称:nsq,代码行数:33,代码来源:http.go
注:本文中的github.com/bitly/nsq/util.ApiResponse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论