bodylimit

package module
v0.0.0-...-dbf7ced Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2017 License: BSD-3-Clause Imports: 2 Imported by: 0

README

Request Body Limit Middleware

Build Status GoDoc Coverage Status

Request Body Limit middleware for Gem Web framework.

Getting Started

Install

$ go get -u github.com/go-gem/middleware-body-limit

Example

package main

import (
	"log"

	"github.com/go-gem/gem"
	"github.com/go-gem/middleware-body-limit"
)

func main() {
	limiter := bodylimit.New(int64(1024))
	router := gem.NewRouter()
	router.POST("/upload", func(ctx *gem.Context) {
		// upload files.
	}, &gem.HandlerOption{Middlewares: []gem.Middleware{limiter}})
	log.Println(gem.ListenAndServe(":8080", router.Handler()))
}

Documentation

Overview

Package bodylimit is a HTTP middleware that limit the request body size.

Example

package main

import (
	"log"

	"github.com/go-gem/gem"
	"github.com/go-gem/middleware-body-limit"
)

func main() {
	// maximum size: 2M.
	limiter := bodylimit.New(int64(2 * 1024))
	router := gem.NewRouter()
	router.POST("/upload", func(ctx *gem.Context) {
		// upload files.
	}, &gem.HandlerOption{Middlewares: []gem.Middleware{limiter}})
	log.Println(gem.ListenAndServe(":8080", router.Handler()))
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter request body limit middleware.

func New

func New(max int64) *Limiter

New returns Limiter instance by the given maximum allowed size.

func (*Limiter) Wrap

func (l *Limiter) Wrap(next gem.Handler) gem.Handler

Wrap implements Middleware's interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL