1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 21:07:03 +00:00
Former-commit-id: 8a8a25ab8fb33a342c8d05fc7eae7cafd5bb02b2
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-03-13 01:40:57 +02:00
parent 5667bfb9f0
commit d76d9b1ec6
10 changed files with 1017 additions and 71 deletions

View File

@@ -164,8 +164,12 @@ var _ ContextPool = &contextPool{}
func (c *contextPool) Acquire(w http.ResponseWriter, r *http.Request) *Context {
ctx := c.pool.Get().(*Context)
ctx.Middleware = nil
ctx.session = nil
ctx.ResponseWriter = acquireResponseWriter(w)
ctx.Request = r
ctx.values = ctx.values[0:0]
return ctx
}
@@ -173,13 +177,8 @@ func (c *contextPool) Release(ctx *Context) {
// flush the body (on recorder) or just the status code (on basic response writer)
// when all finished
ctx.ResponseWriter.flushResponse()
ctx.Middleware = nil
ctx.session = nil
ctx.Request = nil
///TODO:
ctx.ResponseWriter.releaseMe()
ctx.values.Reset()
c.pool.Put(ctx)
}
@@ -810,8 +809,8 @@ func (ctx *Context) WriteGzip(b []byte) (int, error) {
ctx.ResponseWriter.Header().Add(varyHeader, acceptEncodingHeader)
gzipWriter := acquireGzipWriter(ctx.ResponseWriter)
defer releaseGzipWriter(gzipWriter)
n, err := gzipWriter.Write(b)
releaseGzipWriter(gzipWriter)
if err == nil {
ctx.SetHeader(contentEncodingHeader, "gzip")
@@ -1307,6 +1306,28 @@ func (ctx *Context) ParamInt(key string) (int, error) {
return ctx.GetInt(key)
}
// ParamIntWildcard removes the first slash if found and
// returns the int representation of the key's wildcard path parameter's value.
//
// Returns -1 with an error if the parameter couldn't be found.
func (ctx *Context) ParamIntWildcard(key string) (int, error) {
v := ctx.Get(key)
if v != nil {
if vint, ok := v.(int); ok {
return vint, nil
} else if vstring, sok := v.(string); sok {
if len(vstring) > 1 {
if vstring[0] == '/' {
vstring = vstring[1:]
}
}
return strconv.Atoi(vstring)
}
}
return -1, errIntParse.Format(v)
}
// ParamInt64 returns the int64 representation of the key's path named parameter's value
func (ctx *Context) ParamInt64(key string) (int64, error) {
return strconv.ParseInt(ctx.Param(key), 10, 64)