limits

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2025 License: MIT Imports: 4 Imported by: 87 modules, 79 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

size

Run Tests codecov Go Report Card GoDoc

Limit size of POST requests for Gin framework

Example

package main

import (
  "net/http"

  limits "github.com/gin-contrib/size"
  "github.com/gin-gonic/gin"
)

func handler(ctx *gin.Context) {
  val := ctx.PostForm("b")
  if len(ctx.Errors) > 0 {
    return
  }
  ctx.String(http.StatusOK, "got %s\n", val)
}

func main() {
  r := gin.Default()
  r.Use(limits.RequestSizeLimiter(10))
  r.POST("/", handler)
  if err := r.Run(":8080"); err != nil {
    log.Fatal(err)
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestSizeLimiter

func RequestSizeLimiter(limit int64) gin.HandlerFunc

RequestSizeLimiter returns a middleware that limits the size of request When a request is over the limit, the following will happen: * Error will be added to the context * Connection: close header will be set * Error 413 will be sent to the client (http.StatusRequestEntityTooLarge) * Current context will be aborted

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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