本文整理汇总了Golang中github.com/buaazp/fasthttprouter.Params类的典型用法代码示例。如果您正苦于以下问题:Golang Params类的具体用法?Golang Params怎么用?Golang Params使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Params类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetPostJSON
// GetPostJSON is the API method for getting a post's JSON.
func GetPostJSON(ctx *fasthttp.RequestCtx, ps fasthttprouter.Params) {
id := ps.ByName("id")
postJSON, err := model.GetJSON([]byte(id), s)
if err != nil {
ctx.Error(err.Error(), fasthttp.StatusNotFound)
return
}
ctx.Response.Header.Set("Content-Type", "application/json")
ctx.Write(postJSON)
}
开发者ID:bentranter,项目名称:lazyblog,代码行数:11,代码来源:handler.go
示例2: pubRawHandler
// /raw/msgs/:topic/:ver
func (this *Gateway) pubRawHandler(ctx *fasthttp.RequestCtx, params fasthttprouter.Params) {
var (
topic string
ver string
appid string
pubkey string
)
ver = params.ByName(UrlParamVersion)
topic = params.ByName(UrlParamTopic)
header := ctx.Request.Header
appid = string(header.Peek(HttpHeaderAppid))
pubkey = string(header.Peek(HttpHeaderPubkey))
if err := manager.Default.OwnTopic(appid, pubkey, topic); err != nil {
log.Error("app[%s] %s %+v: %v", appid, ctx.RemoteAddr(), params, err)
ctx.SetConnectionClose()
ctx.Error("invalid secret", fasthttp.StatusUnauthorized)
return
}
cluster, found := manager.Default.LookupCluster(appid)
if !found {
log.Error("cluster not found for app: %s", appid)
ctx.Error("invalid appid", fasthttp.StatusBadRequest)
return
}
var out = map[string]string{
"store": "kafka",
"broker.list": strings.Join(meta.Default.BrokerList(cluster), ","),
"topic": manager.Default.KafkaTopic(appid, topic, ver),
}
b, _ := json.Marshal(out)
ctx.SetContentType("application/json; charset=utf8")
ctx.Write(b)
}
开发者ID:funkygao,项目名称:gafka,代码行数:41,代码来源:handler_fastpub.go
示例3: MultiParams
// MultiParams is the multi params handler
func MultiParams(ctx *fasthttp.RequestCtx, ps fasthttprouter.Params) {
fmt.Fprintf(ctx, "hi, %s, %s!\n", ps.ByName("name"), ps.ByName("word"))
}
开发者ID:Taik,项目名称:zing-mp3,代码行数:4,代码来源:basic.go
示例4: Hello
// Hello is the Hello handler
func Hello(ctx *fasthttp.RequestCtx, ps fasthttprouter.Params) {
fmt.Fprintf(ctx, "hello, %s!\n", ps.ByName("name"))
}
开发者ID:Taik,项目名称:zing-mp3,代码行数:4,代码来源:basic.go
示例5: pubHandler
// /topics/:topic/:ver?key=mykey&async=1&delay=100
func (this *Gateway) pubHandler(ctx *fasthttp.RequestCtx, params fasthttprouter.Params) {
t1 := time.Now()
topic := params.ByName(UrlParamTopic)
header := ctx.Request.Header
appid := string(header.Peek(HttpHeaderAppid))
pubkey := string(header.Peek(HttpHeaderPubkey))
if err := manager.Default.OwnTopic(appid, pubkey, topic); err != nil {
log.Error("app[%s] %s %+v: %v", appid, ctx.RemoteAddr(), params, err)
ctx.SetConnectionClose()
ctx.Error("invalid secret", fasthttp.StatusUnauthorized)
return
}
msgLen := ctx.Request.Header.ContentLength()
switch {
case msgLen == -1:
log.Warn("pub[%s] %s %+v invalid content length", appid, ctx.RemoteAddr(), params)
ctx.Error("invalid content length", fasthttp.StatusBadRequest)
return
case int64(msgLen) > options.MaxPubSize:
log.Warn("pub[%s] %s %+v too big content length:%d", appid, ctx.RemoteAddr(), params, msgLen)
ctx.Error(ErrTooBigPubMessage.Error(), fasthttp.StatusBadRequest)
return
case msgLen < options.MinPubSize:
log.Warn("pub[%s] %s %+v too small content length:%d", appid, ctx.RemoteAddr(), params, msgLen)
ctx.Error(ErrTooSmallPubMessage.Error(), fasthttp.StatusBadRequest)
return
}
ver := params.ByName(UrlParamVersion)
queryArgs := ctx.Request.URI().QueryArgs()
key := queryArgs.Peek("key")
asyncArg := queryArgs.Peek("async")
async := len(asyncArg) == 1 && asyncArg[0] == '1'
//delay := hack.String(queryArgs.Peek("delay"))
if options.Debug {
log.Debug("pub[%s] %s {topic:%s, ver:%s, key:%s, async:%+v} %s",
appid, ctx.RemoteAddr(),
topic, ver, key, async,
string(ctx.Request.Body()))
}
if !options.DisableMetrics {
this.pubMetrics.PubQps.Mark(1)
this.pubMetrics.PubMsgSize.Update(int64(len(ctx.PostBody())))
}
pubMethod := store.DefaultPubStore.SyncPub
if async {
pubMethod = store.DefaultPubStore.AsyncPub
}
cluster, found := manager.Default.LookupCluster(appid)
if !found {
log.Error("cluster not found for app: %s", appid)
ctx.Error("invalid appid", fasthttp.StatusBadRequest)
return
}
err := pubMethod(cluster,
manager.Default.KafkaTopic(appid, topic, ver),
key, ctx.PostBody())
if err != nil {
if !options.DisableMetrics {
this.pubMetrics.PubFail(appid, topic, ver)
}
log.Error("%s: %v", ctx.RemoteAddr(), err)
ctx.Error(err.Error(), fasthttp.StatusInternalServerError)
return
}
// write the reponse
ctx.Write(ResponseOk)
if !options.DisableMetrics {
this.pubMetrics.PubOk(appid, topic, ver)
this.pubMetrics.PubLatency.Update(time.Since(t1).Nanoseconds() / 1e6) // in ms
}
}
开发者ID:funkygao,项目名称:gafka,代码行数:87,代码来源:handler_fastpub.go
注:本文中的github.com/buaazp/fasthttprouter.Params类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论