MCPcopy
hub / github.com/gin-gonic/gin / New

Function New

gin.go:202–233  ·  gin.go::New

New returns a new blank Engine instance without any middleware attached. By default, the configuration is: - RedirectTrailingSlash: true - RedirectFixedPath: false - HandleMethodNotAllowed: false - ForwardedByClientIP: true - UseRawPath: false - UseEscapedPath: false - Unesca

(opts ...OptionFunc)

Source from the content-addressed store, hash-verified

200// - UseEscapedPath: false
201// - UnescapePathValues: true
202func New(opts ...OptionFunc) *Engine {
203 debugPrintWARNINGNew()
204 engine := &Engine{
205 RouterGroup: RouterGroup{
206 Handlers: nil,
207 basePath: "/",
208 root: true,
209 },
210 FuncMap: template.FuncMap{},
211 RedirectTrailingSlash: true,
212 RedirectFixedPath: false,
213 HandleMethodNotAllowed: false,
214 ForwardedByClientIP: true,
215 RemoteIPHeaders: []string{"X-Forwarded-For", "X-Real-IP"},
216 TrustedPlatform: defaultPlatform,
217 UseRawPath: false,
218 UseEscapedPath: false,
219 RemoveExtraSlash: false,
220 UnescapePathValues: true,
221 MaxMultipartMemory: defaultMultipartMemory,
222 trees: make(methodTrees, 0, 9),
223 delims: render.Delims{Left: "{{", Right: "}}"},
224 secureJSONPrefix: "while(1);",
225 trustedProxies: []string{"0.0.0.0/0", "::/0"},
226 trustedCIDRs: defaultTrustedCIDRs,
227 }
228 engine.engine = engine
229 engine.pool.New = func() any {
230 return engine.allocateContext(engine.maxParams)
231 }
232 return engine.With(opts...)
233}
234
235// Default returns an Engine instance with the Logger and Recovery middleware already attached.
236func Default(opts ...OptionFunc) *Engine {

Callers 15

TestMiddlewareNoRouteFunction · 0.85
TestMiddlewareAbortFunction · 0.85
TestMiddlewareWriteFunction · 0.85
TestPanicCleanFunction · 0.85
TestPanicInHandlerFunction · 0.85
TestPanicWithAbortFunction · 0.85
TestPanicWithBrokenPipeFunction · 0.85

Calls 3

allocateContextMethod · 0.95
WithMethod · 0.95
debugPrintWARNINGNewFunction · 0.85

Tested by 15

TestMiddlewareNoRouteFunction · 0.68
TestMiddlewareAbortFunction · 0.68
TestMiddlewareWriteFunction · 0.68
TestPanicCleanFunction · 0.68
TestPanicInHandlerFunction · 0.68
TestPanicWithAbortFunction · 0.68
TestPanicWithBrokenPipeFunction · 0.68