gin

package module
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 44 Imported by: 191,418

README

Gin Web Framework

Build Status Trivy Security Scan codecov Go Report Card Go Reference Sourcegraph Open Source Helpers Release

📰 Announcing Gin 1.12.0!

Read about the latest features and improvements in Gin 1.11.0 on our official blog.


Gin is a high-performance HTTP web framework written in Go. It provides a Martini-like API but with significantly better performance—up to 40 times faster—thanks to httprouter. Gin is designed for building REST APIs, web applications, and microservices where speed and developer productivity are essential.

Why choose Gin?

Gin combines the simplicity of Express.js-style routing with Go's performance characteristics, making it ideal for:

  • Building high-throughput REST APIs
  • Developing microservices that need to handle many concurrent requests
  • Creating web applications that require fast response times
  • Prototyping web services quickly with minimal boilerplate

Gin's key features:

  • Zero allocation router - Extremely memory-efficient routing with no heap allocations
  • High performance - Benchmarks show superior speed compared to other Go web frameworks
  • Middleware support - Extensible middleware system for authentication, logging, CORS, etc.
  • Crash-free - Built-in recovery middleware prevents panics from crashing your server
  • JSON validation - Automatic request/response JSON binding and validation
  • Route grouping - Organize related routes and apply common middleware
  • Error management - Centralized error handling and logging
  • Built-in rendering - Support for JSON, XML, HTML templates, and more
  • Extensible - Large ecosystem of community middleware and plugins

Getting Started

Prerequisites
  • Go version: Gin requires Go version 1.25 or above
  • Basic Go knowledge: Familiarity with Go syntax and package management is helpful
Installation

With Go's module support, simply import Gin in your code and Go will automatically fetch it during build:

import "github.com/gin-gonic/gin"
Your First Gin Application

Here's a complete example that demonstrates Gin's simplicity:

package main

import (
  "log"
  "net/http"

  "github.com/gin-gonic/gin"
)

func main() {
  // Create a Gin router with default middleware (logger and recovery)
  r := gin.Default()

  // Define a simple GET endpoint
  r.GET("/ping", func(c *gin.Context) {
    // Return JSON response
    c.JSON(http.StatusOK, gin.H{
      "message": "pong",
    })
  })

  // Start server on port 8080 (default)
  // Server will listen on 0.0.0.0:8080 (localhost:8080 on Windows)
  if err := r.Run(); err != nil {
    log.Fatalf("failed to run server: %v", err)
  }
}

Running the application:

  1. Save the code above as main.go

  2. Run the application:

    go run main.go
    
  3. Open your browser and visit http://localhost:8080/ping

  4. You should see: {"message":"pong"}

What this example demonstrates:

  • Creating a Gin router with default middleware
  • Defining HTTP endpoints with simple handler functions
  • Returning JSON responses
  • Starting an HTTP server
Next Steps

After running your first Gin application, explore these resources to learn more:

📚 Learning Resources
  • Gin Quick Start Guide - Comprehensive tutorial with API examples and build configurations
  • Example Repository - Ready-to-run examples demonstrating various Gin use cases:
    • REST API development
    • Authentication & middleware
    • File uploads and downloads
    • WebSocket connections
    • Template rendering

📖 Documentation

API Reference
User Guides

The comprehensive documentation is available on gin-gonic.com in multiple languages:

Official Tutorials

⚡ Performance Benchmarks

Gin demonstrates exceptional performance compared to other Go web frameworks. It uses a custom version of HttpRouter for maximum efficiency. View detailed benchmarks →

Gin vs. Other Go Frameworks (GitHub API routing benchmark):

Benchmark name (1) (2) (3) (4)
BenchmarkGin_GithubAll 43550 27364 ns/op 0 B/op 0 allocs/op
BenchmarkAce_GithubAll 40543 29670 ns/op 0 B/op 0 allocs/op
BenchmarkAero_GithubAll 57632 20648 ns/op 0 B/op 0 allocs/op
BenchmarkBear_GithubAll 9234 216179 ns/op 86448 B/op 943 allocs/op
BenchmarkBeego_GithubAll 7407 243496 ns/op 71456 B/op 609 allocs/op
BenchmarkBone_GithubAll 420 2922835 ns/op 720160 B/op 8620 allocs/op
BenchmarkChi_GithubAll 7620 238331 ns/op 87696 B/op 609 allocs/op
BenchmarkDenco_GithubAll 18355 64494 ns/op 20224 B/op 167 allocs/op
BenchmarkEcho_GithubAll 31251 38479 ns/op 0 B/op 0 allocs/op
BenchmarkGocraftWeb_GithubAll 4117 300062 ns/op 131656 B/op 1686 allocs/op
BenchmarkGoji_GithubAll 3274 416158 ns/op 56112 B/op 334 allocs/op
BenchmarkGojiv2_GithubAll 1402 870518 ns/op 352720 B/op 4321 allocs/op
BenchmarkGoJsonRest_GithubAll 2976 401507 ns/op 134371 B/op 2737 allocs/op
BenchmarkGoRestful_GithubAll 410 2913158 ns/op 910144 B/op 2938 allocs/op
BenchmarkGorillaMux_GithubAll 346 3384987 ns/op 251650 B/op 1994 allocs/op
BenchmarkGowwwRouter_GithubAll 10000 143025 ns/op 72144 B/op 501 allocs/op
BenchmarkHttpRouter_GithubAll 55938 21360 ns/op 0 B/op 0 allocs/op
BenchmarkHttpTreeMux_GithubAll 10000 153944 ns/op 65856 B/op 671 allocs/op
BenchmarkKocha_GithubAll 10000 106315 ns/op 23304 B/op 843 allocs/op
BenchmarkLARS_GithubAll 47779 25084 ns/op 0 B/op 0 allocs/op
BenchmarkMacaron_GithubAll 3266 371907 ns/op 149409 B/op 1624 allocs/op
BenchmarkMartini_GithubAll 331 3444706 ns/op 226551 B/op 2325 allocs/op
BenchmarkPat_GithubAll 273 4381818 ns/op 1483152 B/op 26963 allocs/op
BenchmarkPossum_GithubAll 10000 164367 ns/op 84448 B/op 609 allocs/op
BenchmarkR2router_GithubAll 10000 160220 ns/op 77328 B/op 979 allocs/op
BenchmarkRivet_GithubAll 14625 82453 ns/op 16272 B/op 167 allocs/op
BenchmarkTango_GithubAll 6255 279611 ns/op 63826 B/op 1618 allocs/op
BenchmarkTigerTonic_GithubAll 2008 687874 ns/op 193856 B/op 4474 allocs/op
BenchmarkTraffic_GithubAll 355 3478508 ns/op 820744 B/op 14114 allocs/op
BenchmarkVulcan_GithubAll 6885 193333 ns/op 19894 B/op 609 allocs/op
  • (1): Total Repetitions achieved in constant time, higher means more confident result
  • (2): Single Repetition Duration (ns/op), lower is better
  • (3): Heap Memory (B/op), lower is better
  • (4): Average Allocations per Repetition (allocs/op), lower is better

🔌 Middleware Ecosystem

Gin has a rich ecosystem of middleware for common web development needs. Explore community-contributed middleware:

  • gin-contrib - Official middleware collection including:
    • Authentication (JWT, Basic Auth, Sessions)
    • CORS, Rate limiting, Compression
    • Logging, Metrics, Tracing
    • Static file serving, Template engines
  • gin-gonic/contrib - Additional community middleware

🏢 Production Usage

Gin powers many high-traffic applications and services in production:

  • gorush - High-performance push notification server
  • fnproject - Container-native, serverless platform
  • photoprism - AI-powered personal photo management
  • lura - Ultra-performant API Gateway framework
  • picfit - Real-time image processing server
  • dkron - Distributed job scheduling system

🤝 Contributing

Gin is the work of hundreds of contributors from around the world. We welcome and appreciate your contributions!

How to Contribute
  • 🐛 Report bugs - Help us identify and fix issues
  • 💡 Suggest features - Share your ideas for improvements
  • 📝 Improve documentation - Help make our docs clearer
  • 🔧 Submit code - Fix bugs or implement new features
  • 🧪 Write tests - Improve our test coverage
Getting Started with Contributing
  1. Check out our CONTRIBUTING.md for detailed guidelines
  2. Join our community discussions and ask questions

All contributions are valued and help make Gin better for everyone!

Documentation

Overview

Package gin implements a HTTP web framework called gin.

See https://gin-gonic.com/ for more information about gin.

Example:

package main

import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.Run() // listen and serve on 0.0.0.0:8080
}

Index

Constants

View Source
const (
	MIMEJSON              = binding.MIMEJSON
	MIMEHTML              = binding.MIMEHTML
	MIMEXML               = binding.MIMEXML
	MIMEXML2              = binding.MIMEXML2
	MIMEPlain             = binding.MIMEPlain
	MIMEPOSTForm          = binding.MIMEPOSTForm
	MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
	MIMEYAML              = binding.MIMEYAML
	MIMEYAML2             = binding.MIMEYAML2
	MIMETOML              = binding.MIMETOML
	MIMEPROTOBUF          = binding.MIMEPROTOBUF
	MIMEBSON              = binding.MIMEBSON
)

Content-Type MIME of the most common data formats.

View Source
const (
	// PlatformGoogleAppEngine when running on Google App Engine. Trust X-Appengine-Remote-Addr
	// for determining the client's IP
	PlatformGoogleAppEngine = "X-Appengine-Remote-Addr"
	// PlatformCloudflare when using Cloudflare's CDN. Trust CF-Connecting-IP for determining
	// the client's IP
	PlatformCloudflare = "CF-Connecting-IP"
	// PlatformFlyIO when running on Fly.io. Trust Fly-Client-IP for determining the client's IP
	PlatformFlyIO = "Fly-Client-IP"
)

Trusted platforms

View Source
const (
	// DebugMode indicates gin mode is debug.
	DebugMode = "debug"
	// ReleaseMode indicates gin mode is release.
	ReleaseMode = "release"
	// TestMode indicates gin mode is test.
	TestMode = "test"
)
View Source
const AuthProxyUserKey = "proxy_user"

AuthProxyUserKey is the cookie name for proxy_user credential in basic auth for proxy.

View Source
const AuthUserKey = "user"

AuthUserKey is the cookie name for user credential in basic auth.

View Source
const BindKey = "_gin-gonic/gin/bindkey"

BindKey indicates a default bind key.

View Source
const BodyBytesKey = "_gin-gonic/gin/bodybyteskey"

BodyBytesKey indicates a default body bytes key.

View Source
const ContextKey = "_gin-gonic/gin/contextkey"

ContextKey is the key that a Context returns itself for.

View Source
const EnvGinMode = "GIN_MODE"

EnvGinMode indicates environment name for gin mode.

View Source
const Version = "v1.12.0"

Version is the current gin framework's version.

Variables

View Source
var DebugPrintFunc func(format string, values ...any)

DebugPrintFunc indicates debug log output format.

View Source
var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)

DebugPrintRouteFunc indicates debug log output format.

View Source
var DefaultErrorWriter io.Writer = os.Stderr

DefaultErrorWriter is the default io.Writer used by Gin to debug errors

View Source
var DefaultWriter io.Writer = os.Stdout

DefaultWriter is the default io.Writer used by Gin for debug output and middleware output like Logger() or Recovery(). Note that both Logger and Recovery provides custom ways to configure their output io.Writer. To support coloring in Windows use:

import "github.com/mattn/go-colorable"
gin.DefaultWriter = colorable.NewColorableStdout()

Functions

func CreateTestContext added in v1.3.0

func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine)

CreateTestContext returns a fresh Engine and a Context associated with it. This is useful for tests that need to set up a new Gin engine instance along with a context, for example, to test middleware that doesn't depend on specific routes. The ResponseWriter `w` is used to initialize the context's writer.

func Dir

func Dir(root string, listDirectory bool) http.FileSystem

Dir returns an http.FileSystem that can be used by http.FileServer(). It is used internally in router.Static(). if listDirectory == true, then it works the same as http.Dir(), otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.

func DisableBindValidation

func DisableBindValidation()

DisableBindValidation closes the default validator.

func DisableConsoleColor added in v1.3.0

func DisableConsoleColor()

DisableConsoleColor disables color output in the console.

func EnableJsonDecoderDisallowUnknownFields added in v1.5.0

func EnableJsonDecoderDisallowUnknownFields()

EnableJsonDecoderDisallowUnknownFields sets true for binding.EnableDecoderDisallowUnknownFields to call the DisallowUnknownFields method on the JSON Decoder instance.

func EnableJsonDecoderUseNumber added in v1.3.0

func EnableJsonDecoderUseNumber()

EnableJsonDecoderUseNumber sets true for binding.EnableDecoderUseNumber to call the UseNumber method on the JSON Decoder instance.

func ForceConsoleColor added in v1.4.0

func ForceConsoleColor()

ForceConsoleColor force color output in the console.

func IsDebugging

func IsDebugging() bool

IsDebugging returns true if the framework is running in debug mode. Use SetMode(gin.ReleaseMode) to disable debug mode.

func Mode

func Mode() string

Mode returns current gin mode.

func SetMode

func SetMode(value string)

SetMode sets gin mode according to input string.

Types

type Accounts

type Accounts map[string]string

Accounts defines a key/value for user/pass list of authorized logins.

type Context

type Context struct {
	Request *http.Request
	Writer  ResponseWriter

	Params Params

	// Keys is a key/value pair exclusively for the context of each request.
	Keys map[any]any

	// Errors is a list of errors attached to all the handlers/middlewares who used this context.
	Errors errorMsgs

	// Accepted defines a list of manually accepted formats for content negotiation.
	Accepted []string
	// contains filtered or unexported fields
}

Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.

func CreateTestContextOnly added in v1.8.2

func CreateTestContextOnly(w http.ResponseWriter, r *Engine) (c *Context)

CreateTestContextOnly returns a fresh Context associated with the provided Engine `r`. This is useful for tests that operate on an existing, possibly pre-configured, Gin engine instance and need a new context for it. The ResponseWriter `w` is used to initialize the context's writer. The context is allocated with the `maxParams` setting from the provided engine.

func (*Context) Abort

func (c *Context) Abort()

Abort prevents pending handlers from being called. Note that this will not stop the current handler. Let's say you have an authorization middleware that validates that the current request is authorized. If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers for this request are not called.

func (*Context) AbortWithError

func (c *Context) AbortWithError(code int, err error) *Error

AbortWithError calls `AbortWithStatus()` and `Error()` internally. This method stops the chain, writes the status code and pushes the specified error to `c.Errors`. See Context.Error() for more details.

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

AbortWithStatus calls `Abort()` and writes the headers with the specified status code. For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401).

func (*Context) AbortWithStatusJSON added in v1.3.0

func (c *Context) AbortWithStatusJSON(code int, jsonObj any)

AbortWithStatusJSON calls `Abort()` and then `JSON` internally. This method stops the chain, writes the status code and return a JSON body. It also sets the Content-Type as "application/json".

func (*Context) AbortWithStatusPureJSON added in v1.11.0

func (c *Context) AbortWithStatusPureJSON(code int, jsonObj any)

AbortWithStatusPureJSON calls `Abort()` and then `PureJSON` internally. This method stops the chain, writes the status code and return a JSON body without escaping. It also sets the Content-Type as "application/json".

func (*Context) AddParam added in v1.8.0

func (c *Context) AddParam(key, value string)

AddParam adds param to context and replaces path param key with given value for e2e testing purposes Example Route: "/user/:id" AddParam("id", 1) Result: "/user/1"

func (*Context) AsciiJSON added in v1.3.0

func (c *Context) AsciiJSON(code int, obj any)

AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string. It also sets the Content-Type as "application/json".

func (*Context) BSON added in v1.12.0

func (c *Context) BSON(code int, obj any)

BSON serializes the given struct as BSON into the response body.

func (*Context) Bind

func (c *Context) Bind(obj any) error

Bind checks the Method and Content-Type to select a binding engine automatically, Depending on the "Content-Type" header different bindings are used, for example:

"application/json" --> JSON binding
"application/xml"  --> XML binding

It parses the request's body based on the Content-Type (e.g., JSON or XML). It decodes the payload into the struct specified as a pointer. It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.

func (*Context) BindHeader added in v1.5.0

func (c *Context) BindHeader(obj any) error

BindHeader is a shortcut for c.MustBindWith(obj, binding.Header).

func (*Context) BindJSON

func (c *Context) BindJSON(obj any) error

BindJSON is a shortcut for c.MustBindWith(obj, binding.JSON).

func (*Context) BindPlain added in v1.11.0

func (c *Context) BindPlain(obj any) error

BindPlain is a shortcut for c.MustBindWith(obj, binding.Plain).

func (*Context) BindQuery added in v1.3.0

func (c *Context) BindQuery(obj any) error

BindQuery is a shortcut for c.MustBindWith(obj, binding.Query).

func (*Context) BindTOML added in v1.8.0

func (c *Context) BindTOML(obj any) error

BindTOML is a shortcut for c.MustBindWith(obj, binding.TOML).

func (*Context) BindUri added in v1.4.0

func (c *Context) BindUri(obj any) error

BindUri binds the passed struct pointer using binding.Uri. It will abort the request with HTTP 400 if any error occurs.

func (*Context) BindWith deprecated

func (c *Context) BindWith(obj any, b binding.Binding) error

BindWith binds the passed struct pointer using the specified binding engine. See the binding package.

Deprecated: Use MustBindWith or ShouldBindWith.

func (*Context) BindXML added in v1.4.0

func (c *Context) BindXML(obj any) error

BindXML is a shortcut for c.MustBindWith(obj, binding.BindXML).

func (*Context) BindYAML added in v1.4.0

func (c *Context) BindYAML(obj any) error

BindYAML is a shortcut for c.MustBindWith(obj, binding.YAML).

func (*Context) ClientIP

func (c *Context) ClientIP() string

ClientIP implements one best effort algorithm to return the real client IP. It calls c.RemoteIP() under the hood, to check if the remote IP is a trusted proxy or not. If it is it will then try to parse the headers defined in Engine.RemoteIPHeaders (defaulting to [X-Forwarded-For, X-Real-IP]). If the headers are not syntactically valid OR the remote IP does not correspond to a trusted proxy, the remote IP (coming from Request.RemoteAddr) is returned.

func (*Context) ContentType

func (c *Context) ContentType() string

ContentType returns the Content-Type header of the request.

func (*Context) Cookie

func (c *Context) Cookie(name string) (string, error)

Cookie returns the named cookie provided in the request or ErrNoCookie if not found. And return the named cookie is unescaped. If multiple cookies match the given name, only one cookie will be returned.

func (*Context) Copy

func (c *Context) Copy() *Context

Copy returns a copy of the current context that can be safely used outside the request's scope. This has to be used when the context has to be passed to a goroutine.

func (*Context) Data

func (c *Context) Data(code int, contentType string, data []byte)

Data writes some data into the body stream and updates the HTTP code.

func (*Context) DataFromReader added in v1.3.0

func (c *Context) DataFromReader(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string)

DataFromReader writes the specified reader into the body stream and updates the HTTP code.

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

Deadline returns that there is no deadline (ok==false) when c.Request has no Context.

func (*Context) DefaultPostForm

func (c *Context) DefaultPostForm(key, defaultValue string) string

DefaultPostForm returns the specified key from a POST urlencoded form or multipart form when it exists, otherwise it returns the specified defaultValue string. See: PostForm() and GetPostForm() for further information.

func (*Context) DefaultQuery

func (c *Context) DefaultQuery(key, defaultValue string) string

DefaultQuery returns the keyed url query value if it exists, otherwise it returns the specified defaultValue string. See: Query() and GetQuery() for further information.

GET /?name=Manu&lastname=
c.DefaultQuery("name", "unknown") == "Manu"
c.DefaultQuery("id", "none") == "none"
c.DefaultQuery("lastname", "none") == ""

func (*Context) Delete added in v1.12.0

func (c *Context) Delete(key any)

Delete deletes the key from the Context's Key map, if it exists. This operation is safe to be used by concurrent go-routines

func (*Context) Done

func (c *Context) Done() <-chan struct{}

Done returns nil (chan which will wait forever) when c.Request has no Context.

func (*Context) Err

func (c *Context) Err() error

Err returns nil when c.Request has no Context.

func (*Context) Error

func (c *Context) Error(err error) *Error

Error attaches an error to the current context. The error is pushed to a list of errors. It's a good idea to call Error for each error that occurred during the resolution of a request. A middleware can be used to collect all the errors and push them to a database together, print a log, or append it in the HTTP response. Error will panic if err is nil.

func (*Context) File

func (c *Context) File(filepath string)

File writes the specified file into the body stream in an efficient way.

func (*Context) FileAttachment added in v1.4.0

func (c *Context) FileAttachment(filepath, filename string)

FileAttachment writes the specified file into the body stream in an efficient way On the client side, the file will typically be downloaded with the given filename

func (*Context) FileFromFS added in v1.6.0

func (c *Context) FileFromFS(filepath string, fs http.FileSystem)

FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.

func (*Context) FormFile added in v1.3.0

func (c *Context) FormFile(name string) (*multipart.FileHeader, error)

FormFile returns the first file for the provided form key.

func (*Context) FullPath added in v1.5.0

func (c *Context) FullPath() string

FullPath returns a matched route full path. For not found routes returns an empty string.

router.GET("/user/:id", func(c *gin.Context) {
    c.FullPath() == "/user/:id" // true
})

func (*Context) Get

func (c *Context) Get(key any) (value any, exists bool)

Get returns the value for the given key, ie: (value, true). If the value does not exist it returns (nil, false)

func (*Context) GetBool added in v1.3.0

func (c *Context) GetBool(key any) bool

GetBool returns the value associated with the key as a boolean.

func (*Context) GetDuration added in v1.3.0

func (c *Context) GetDuration(key any) time.Duration

GetDuration returns the value associated with the key as a duration.

func (*Context) GetError added in v1.12.0

func (c *Context) GetError(key any) error

GetError returns the value associated with the key as an error.

func (*Context) GetErrorSlice added in v1.12.0

func (c *Context) GetErrorSlice(key any) []error

GetErrorSlice returns the value associated with the key as a slice of errors.

func (*Context) GetFloat32 added in v1.11.0

func (c *Context) GetFloat32(key any) float32

GetFloat32 returns the value associated with the key as a float32.

func (*Context) GetFloat32Slice added in v1.11.0

func (c *Context) GetFloat32Slice(key any) []float32

GetFloat32Slice returns the value associated with the key as a slice of float32 numbers.

func (*Context) GetFloat64 added in v1.3.0

func (c *Context) GetFloat64(key any) float64

GetFloat64 returns the value associated with the key as a float64.

func (*Context) GetFloat64Slice added in v1.11.0

func (c *Context) GetFloat64Slice(key any) []float64

GetFloat64Slice returns the value associated with the key as a slice of float64 numbers.

func (*Context) GetHeader added in v1.3.0

func (c *Context) GetHeader(key string) string

GetHeader returns value from request headers.

func (*Context) GetInt added in v1.3.0

func (c *Context) GetInt(key any) int

GetInt returns the value associated with the key as an integer.

func (*Context) GetInt8 added in v1.11.0

func (c *Context) GetInt8(key any) int8

GetInt8 returns the value associated with the key as an integer 8.

func (*Context) GetInt8Slice added in v1.11.0

func (c *Context) GetInt8Slice(key any) []int8

GetInt8Slice returns the value associated with the key as a slice of int8 integers.

func (*Context) GetInt16 added in v1.11.0

func (c *Context) GetInt16(key any) int16

GetInt16 returns the value associated with the key as an integer 16.

func (*Context) GetInt16Slice added in v1.11.0

func (c *Context) GetInt16Slice(key any) []int16

GetInt16Slice returns the value associated with the key as a slice of int16 integers.

func (*Context) GetInt32 added in v1.11.0

func (c *Context) GetInt32(key any) int32

GetInt32 returns the value associated with the key as an integer 32.

func (*Context) GetInt32Slice added in v1.11.0

func (c *Context) GetInt32Slice(key any) []int32

GetInt32Slice returns the value associated with the key as a slice of int32 integers.

func (*Context) GetInt64 added in v1.3.0

func (c *Context) GetInt64(key any) int64

GetInt64 returns the value associated with the key as an integer 64.

func (*Context) GetInt64Slice added in v1.11.0

func (c *Context) GetInt64Slice(key any) []int64

GetInt64Slice returns the value associated with the key as a slice of int64 integers.

func (*Context) GetIntSlice added in v1.11.0

func (c *Context) GetIntSlice(key any) []int

GetIntSlice returns the value associated with the key as a slice of integers.

func (*Context) GetPostForm

func (c *Context) GetPostForm(key string) (string, bool)

GetPostForm is like PostForm(key). It returns the specified key from a POST urlencoded form or multipart form when it exists `(value, true)` (even when the value is an empty string), otherwise it returns ("", false). For example, during a PATCH request to update the user's email:

    email=mail@example.com  -->  ("mail@example.com", true) := GetPostForm("email") // set email to "mail@example.com"
	   email=                  -->  ("", true) := GetPostForm("email") // set email to ""
                            -->  ("", false) := GetPostForm("email") // do nothing with email

func (*Context) GetPostFormArray

func (c *Context) GetPostFormArray(key string) (values []string, ok bool)

GetPostFormArray returns a slice of strings for a given form key, plus a boolean value whether at least one value exists for the given key.

func (*Context) GetPostFormMap added in v1.3.0

func (c *Context) GetPostFormMap(key string) (map[string]string, bool)

GetPostFormMap returns a map for a given form key, plus a boolean value whether at least one value exists for the given key.

func (*Context) GetQuery

func (c *Context) GetQuery(key string) (string, bool)

GetQuery is like Query(), it returns the keyed url query value if it exists `(value, true)` (even when the value is an empty string), otherwise it returns `("", false)`. It is shortcut for `c.Request.URL.Query().Get(key)`

GET /?name=Manu&lastname=
("Manu", true) == c.GetQuery("name")
("", false) == c.GetQuery("id")
("", true) == c.GetQuery("lastname")

func (*Context) GetQueryArray

func (c *Context) GetQueryArray(key string) (values []string, ok bool)

GetQueryArray returns a slice of strings for a given query key, plus a boolean value whether at least one value exists for the given key.

func (*Context) GetQueryMap added in v1.3.0

func (c *Context) GetQueryMap(key string) (map[string]string, bool)

GetQueryMap returns a map for a given query key, plus a boolean value whether at least one value exists for the given key.

func (*Context) GetRawData added in v1.3.0

func (c *Context) GetRawData() ([]byte, error)

GetRawData returns stream data.

func (*Context) GetString added in v1.3.0

func (c *Context) GetString(key any) string

GetString returns the value associated with the key as a string.

func (*Context) GetStringMap added in v1.3.0

func (c *Context) GetStringMap(key any) map[string]any

GetStringMap returns the value associated with the key as a map of interfaces.

func (*Context) GetStringMapString added in v1.3.0

func (c *Context) GetStringMapString(key any) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func (*Context)