{"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"crypto/subtle\"\n\t\"encoding/base64\"\n\t\"net/http\"\n\t\"strconv\"\n\n\t\"github.com/gin-gonic/gin/internal/bytesconv\"\n)\n\n// AuthUserKey is the cookie name for user credential in basic auth.\nconst AuthUserKey = \"user\"\n\n// AuthProxyUserKey is the cookie name for proxy_user credential in basic auth for proxy.\nconst AuthProxyUserKey = \"proxy_user\"\n\n// Accounts defines a key/value for user/pass list of authorized logins.\ntype Accounts ma", "suffix": "range a {\n\t\tif subtle.ConstantTimeCompare(bytesconv.StringToBytes(pair.value), bytesconv.StringToBytes(authValue)) == 1 {\n\t\t\treturn pair.user, true\n\t\t}\n\t}\n\treturn \"\", false\n}\n\n// BasicAuthForRealm returns a Basic HTTP Authorization middleware. It takes as ", "middle": "p[string]string\n\ntype authPair struct {\n\tvalue string\n\tuser string\n}\n\ntype authPairs []authPair\n\nfunc (a authPairs) searchCredential(authValue string) (string, bool) {\n\tif authValue == \"\" {\n\t\treturn \"\", false\n\t}\n\tfor _, pair := ", "meta": {"filepath": "auth.go", "language": "go", "file_size": 3838, "cut_index": 614, "middle_length": 229}} {"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"html/template\"\n\t\"net/http\"\n\t\"os\"\n\t\"testing\"\n)\n\nfunc BenchmarkOneRoute(B *testing.B) {\n\trouter := New()\n\trouter.GET(\"/ping\", func(c *Context) {})\n\trunRequest(B, router, http.MethodGet, \"/ping\")\n}\n\nfunc BenchmarkRecoveryMiddleware(B *testing.B) {\n\trouter := New()\n\trouter.Use(Recovery())\n\trouter.GET(\"/\", func(c *Context) {})\n\trunRequest(B, router, http.MethodGet, \"/\")\n}\n\nfunc BenchmarkLoggerMiddleware(B *testing.B) {\n\trout", "suffix": "oggerWithWriter(newMockWriter()))\n\trouter.Use(func(c *Context) {})\n\trouter.Use(func(c *Context) {})\n\trouter.GET(\"/ping\", func(c *Context) {})\n\trunRequest(B, router, http.MethodGet, \"/ping\")\n}\n\nfunc Benchmark5Params(B *testing.B) {\n\tDefaultWriter = os.Stdou", "middle": "er := New()\n\trouter.Use(LoggerWithWriter(newMockWriter()))\n\trouter.GET(\"/\", func(c *Context) {})\n\trunRequest(B, router, http.MethodGet, \"/\")\n}\n\nfunc BenchmarkManyHandlers(B *testing.B) {\n\trouter := New()\n\trouter.Use(Recovery(), L", "meta": {"filepath": "benchmarks_test.go", "language": "go", "file_size": 3962, "cut_index": 614, "middle_length": 229}} {"prefix": "de == http.StatusForbidden)\n\t})\n\n\t// Test with HEAD request\n\tt.Run(\"HEAD request\", func(t *testing.T) {\n\t\ttestFile := \"testdata/test_file.txt\"\n\n\t\tw := httptest.NewRecorder()\n\t\tc, _ := CreateTestContext(w)\n\t\tc.Request = httptest.NewRequest(http.MethodHead, \"/test\", nil)\n\n\t\tc.File(testFile)\n\n\t\tassert.Equal(t, http.StatusOK, w.Code)\n\t\tassert.Empty(t, w.Body.String()) // HEAD request should not return body\n\t\tassert.Equal(t, \"text/plain; charset=utf-8\", w.Header().Get(\"Content-Type\"))\n\t})\n\n\t// Test with Range re", "suffix": "eader.Set(\"Range\", \"bytes=0-10\")\n\n\t\tc.File(testFile)\n\n\t\tassert.Equal(t, http.StatusPartialContent, w.Code)\n\t\tassert.Equal(t, \"bytes\", w.Header().Get(\"Accept-Ranges\"))\n\t\tassert.Contains(t, w.Header().Get(\"Content-Range\"), \"bytes 0-10\")\n\t})\n}\n\nfunc TestConte", "middle": "quest\n\tt.Run(\"Range request\", func(t *testing.T) {\n\t\ttestFile := \"testdata/test_file.txt\"\n\n\t\tw := httptest.NewRecorder()\n\t\tc, _ := CreateTestContext(w)\n\t\tc.Request = httptest.NewRequest(http.MethodGet, \"/test\", nil)\n\t\tc.Request.H", "meta": {"filepath": "context_test.go", "language": "go", "file_size": 112684, "cut_index": 3790, "middle_length": 229}} {"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n\n\t\"github.com/gin-gonic/gin/codec/json\"\n)\n\n// ErrorType is an unsigned 64-bit error code as defined in the gin spec.\ntype ErrorType uint64\n\nconst (\n\t// ErrorTypeBind is used when Context.Bind() fails.\n\tErrorTypeBind ErrorType = 1 << 63\n\t// ErrorTypeRender is used when Context.Render() fails.\n\tErrorTypeRender ErrorType = 1 << 62\n\t// ErrorTypePrivate indicates a private error.\n\tErrorTypePrivate ", "suffix": "type Error struct {\n\tErr error\n\tType ErrorType\n\tMeta any\n}\n\ntype errorMsgs []*Error\n\nvar _ error = (*Error)(nil)\n\n// SetType sets the error's type.\nfunc (msg *Error) SetType(flags ErrorType) *Error {\n\tmsg.Type = flags\n\treturn msg\n}\n\n// SetMeta sets the er", "middle": "ErrorType = 1 << 0\n\t// ErrorTypePublic indicates a public error.\n\tErrorTypePublic ErrorType = 1 << 1\n\t// ErrorTypeAny indicates any other error.\n\tErrorTypeAny ErrorType = 1<<64 - 1\n)\n\n// Error represents a error's specification.\n", "meta": {"filepath": "errors.go", "language": "go", "file_size": 3944, "cut_index": 614, "middle_length": 229}} {"prefix": "InsecureSkipVerify: true,\n\t\t},\n\t}\n\tclient := &http.Client{Transport: tr}\n\n\tresp, err := client.Get(params[0])\n\trequire.NoError(t, err)\n\tdefer resp.Body.Close()\n\n\tbody, ioerr := io.ReadAll(resp.Body)\n\trequire.NoError(t, ioerr)\n\n\tresponseStatus := \"200 OK\"\n\tif len(params) > 1 && params[1] != \"\" {\n\t\tresponseStatus = params[1]\n\t}\n\n\tresponseBody := \"it worked\"\n\tif len(params) > 2 && params[2] != \"\" {\n\t\tresponseBody = params[2]\n\t}\n\n\tassert.Equal(t, responseStatus, resp.Status, \"should get a \"+responseStatus)\n\tif ", "suffix": "ntext) { c.String(http.StatusOK, \"it worked\") })\n\t\tassert.NoError(t, router.Run())\n\t}()\n\n\t// Wait for server to be ready with exponential backoff\n\terr := waitForServerReady(\"http://localhost:8080/example\", 10)\n\trequire.NoError(t, err, \"server should start ", "middle": "responseStatus == \"200 OK\" {\n\t\tassert.Equal(t, responseBody, string(body), \"resp body should match\")\n\t}\n}\n\nfunc TestRunEmpty(t *testing.T) {\n\tos.Setenv(\"PORT\", \"\")\n\trouter := New()\n\tgo func() {\n\t\trouter.GET(\"/example\", func(c *Co", "meta": {"filepath": "gin_integration_test.go", "language": "go", "file_size": 23533, "cut_index": 1331, "middle_length": 229}} {"prefix": "/http\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/gin-contrib/sse\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc TestMiddlewareGeneralCase(t *testing.T) {\n\tsignature := \"\"\n\trouter := New()\n\trouter.Use(func(c *Context) {\n\t\tsignature += \"A\"\n\t\tc.Next()\n\t\tsignature += \"B\"\n\t})\n\trouter.Use(func(c *Context) {\n\t\tsignature += \"C\"\n\t})\n\trouter.GET(\"/\", func(c *Context) {\n\t\tsignature += \"D\"\n\t})\n\trouter.NoRoute(func(c *Context) {\n\t\tsignature += \" X \"\n\t})\n\trouter.NoMethod(func(c *Context) {\n\t\tsignature += \" XX \"\n\t})\n\t// RUN\n\tw ", "suffix": "(c *Context) {\n\t\tsignature += \"A\"\n\t\tc.Next()\n\t\tsignature += \"B\"\n\t})\n\trouter.Use(func(c *Context) {\n\t\tsignature += \"C\"\n\t\tc.Next()\n\t\tc.Next()\n\t\tc.Next()\n\t\tc.Next()\n\t\tsignature += \"D\"\n\t})\n\trouter.NoRoute(func(c *Context) {\n\t\tsignature += \"E\"\n\t\tc.Next()\n\t\tsign", "middle": ":= PerformRequest(router, http.MethodGet, \"/\")\n\n\t// TEST\n\tassert.Equal(t, http.StatusOK, w.Code)\n\tassert.Equal(t, \"ACDB\", signature)\n}\n\nfunc TestMiddlewareNoRoute(t *testing.T) {\n\tsignature := \"\"\n\trouter := New()\n\trouter.Use(func", "meta": {"filepath": "middleware_test.go", "language": "go", "file_size": 5371, "cut_index": 716, "middle_length": 229}} {"prefix": "ord\"\n\trouter.Use(RecoveryWithWriter(buffer))\n\trouter.GET(\"/recovery\", func(c *Context) {\n\t\tc.AbortWithStatus(http.StatusBadRequest)\n\t\tpanic(\"Oops, Houston, we have a problem\")\n\t})\n\t// RUN\n\tw := PerformRequest(router, http.MethodGet, \"/recovery\",\n\t\theader{\n\t\t\tKey: \"Host\",\n\t\t\tValue: \"www.google.com\",\n\t\t},\n\t\theader{\n\t\t\tKey: \"Authorization\",\n\t\t\tValue: \"Bearer \" + password,\n\t\t},\n\t\theader{\n\t\t\tKey: \"Content-Type\",\n\t\t\tValue: \"application/json\",\n\t\t},\n\t)\n\t// TEST\n\tassert.Equal(t, http.StatusBadRequest, w.Code)\n", "suffix": "ilder)\n\trouter := New()\n\trouter.Use(RecoveryWithWriter(buffer))\n\trouter.GET(\"/recovery\", func(_ *Context) {\n\t\tpanic(\"Oops, Houston, we have a problem\")\n\t})\n\t// RUN\n\tw := PerformRequest(router, http.MethodGet, \"/recovery\")\n\t// TEST\n\tassert.Equal(t, http.Sta", "middle": "\n\t// Check the buffer does not have the secret key\n\tassert.NotContains(t, buffer.String(), password)\n}\n\n// TestPanicInHandler assert that panic has been recovered.\nfunc TestPanicInHandler(t *testing.T) {\n\tbuffer := new(strings.Bu", "meta": {"filepath": "recovery_test.go", "language": "go", "file_size": 10918, "cut_index": 921, "middle_length": 229}} {"prefix": " a boolean false .\nfunc (ps Params) Get(name string) (string, bool) {\n\tfor _, entry := range ps {\n\t\tif entry.Key == name {\n\t\t\treturn entry.Value, true\n\t\t}\n\t}\n\treturn \"\", false\n}\n\n// ByName returns the value of the first Param which key matches the given name.\n// If no matching Param is found, an empty string is returned.\nfunc (ps Params) ByName(name string) (va string) {\n\tva, _ = ps.Get(name)\n\treturn\n}\n\ntype methodTree struct {\n\tmethod string\n\troot *node\n}\n\ntype methodTrees []methodTree\n\nfunc (trees metho", "suffix": "_ && a[i] == b[i] {\n\t\ti++\n\t}\n\treturn i\n}\n\n// addChild will add a child node, keeping wildcardChild at the end\nfunc (n *node) addChild(child *node) {\n\tif n.wildChild && len(n.children) > 0 {\n\t\twildcardChild := n.children[len(n.children)-1]\n\t\tn.children = ap", "middle": "dTrees) get(method string) *node {\n\tfor _, tree := range trees {\n\t\tif tree.method == method {\n\t\t\treturn tree.root\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc longestCommonPrefix(a, b string) int {\n\ti := 0\n\tmax_ := min(len(a), len(b))\n\tfor i < max", "meta": {"filepath": "tree.go", "language": "go", "file_size": 24381, "cut_index": 1331, "middle_length": 229}} {"prefix": "yright 2017 Manu Martinez-Almeida. All rights reserved.\n// Use of this source code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\n//go:build !nomsgpack\n\npackage render\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/ugorji/go/codec\"\n)\n\n// Check interface implemented here to support go build tag nomsgpack.\n// See: https://github.com/gin-gonic/gin/pull/1852/\nvar (\n\t_ Render = MsgPack{}\n)\n\n// MsgPack contains the given interface object.\ntype MsgPack struct {\n\tData any\n}\n\nvar msgpackContentTy", "suffix": "ack) encodes the given interface object and writes data with custom ContentType.\nfunc (r MsgPack) Render(w http.ResponseWriter) error {\n\treturn WriteMsgPack(w, r.Data)\n}\n\n// WriteMsgPack writes MsgPack ContentType and encodes the given interface object.\nfu", "middle": "pe = []string{\"application/msgpack; charset=utf-8\"}\n\n// WriteContentType (MsgPack) writes MsgPack ContentType.\nfunc (r MsgPack) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, msgpackContentType)\n}\n\n// Render (MsgP", "meta": {"filepath": "render/msgpack.go", "language": "go", "file_size": 1175, "cut_index": 518, "middle_length": 229}} {"prefix": "// Copyright 2022 Gin Core Team. All rights reserved.\n// Use of this source code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\npackage render\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/pelletier/go-toml/v2\"\n)\n\n// TOML contains the given interface object.\ntype TOML struct {\n\tData any\n}\n\nvar tomlContentType = []string{\"application/toml; charset=utf-8\"}\n\n// Render (TOML) marshals the given interface object and writes data with custom ContentType.\nfunc (r TOML) Render(w http.ResponseWri", "suffix": "toml.Marshal(r.Data)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = w.Write(bytes)\n\treturn err\n}\n\n// WriteContentType (TOML) writes TOML ContentType for response.\nfunc (r TOML) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, tomlContentType)\n}\n", "middle": "ter) error {\n\tr.WriteContentType(w)\n\n\tbytes, err := ", "meta": {"filepath": "render/toml.go", "language": "go", "file_size": 820, "cut_index": 512, "middle_length": 52}} {"prefix": " 2019 Gin Core Team. All rights reserved.\n// Use of this source code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\npackage binding\n\nimport (\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/stretchr/testify/assert\"\n)\n\nvar form = map[string][]string{\n\t\"name\": {\"mike\"},\n\t\"friends\": {\"anna\", \"nicole\"},\n\t\"id_number\": {\"12345678\"},\n\t\"id_date\": {\"2018-01-20\"},\n}\n\ntype structFull struct {\n\tName string `form:\"name\"`\n\tAge int `form:\"age,default=25\"`\n\tFriends []string `form:\"fri", "suffix": "esting.B) {\n\tvar s structFull\n\tfor b.Loop() {\n\t\terr := mapForm(&s, form)\n\t\tif err != nil {\n\t\t\tb.Fatalf(\"Error on a form mapping\")\n\t\t}\n\t}\n\tb.StopTimer()\n\n\tt := b\n\tassert.Equal(t, \"mike\", s.Name)\n\tassert.Equal(t, 25, s.Age)\n\tassert.Equal(t, []string{\"anna\", ", "middle": "ends\"`\n\tID *struct {\n\t\tNumber string `form:\"id_number\"`\n\t\tDateOfIssue time.Time `form:\"id_date\" time_format:\"2006-01-02\" time_utc:\"true\"`\n\t}\n\tNationality *string `form:\"nationality\"`\n}\n\nfunc BenchmarkMapFormFull(b *t", "meta": {"filepath": "binding/form_mapping_benchmark_test.go", "language": "go", "file_size": 1468, "cut_index": 524, "middle_length": 229}} {"prefix": "tobuf/reflect/protoreflect\"\n\tprotoimpl \"google.golang.org/protobuf/runtime/protoimpl\"\n\treflect \"reflect\"\n\tsync \"sync\"\n)\n\nconst (\n\t// Verify that this generated code is sufficiently up-to-date.\n\t_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)\n\t// Verify that runtime/protoimpl is sufficiently up-to-date.\n\t_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)\n)\n\ntype FOO int32\n\nconst (\n\tFOO_X FOO = 17\n)\n\n// Enum value maps for FOO.\nvar (\n\tFOO_name = map[int32]string{\n\t\t17: \"X\",\n\t}\n\tFOO_value = map[st", "suffix": "otoreflect.EnumDescriptor {\n\treturn file_test_proto_enumTypes[0].Descriptor()\n}\n\nfunc (FOO) Type() protoreflect.EnumType {\n\treturn &file_test_proto_enumTypes[0]\n}\n\nfunc (x FOO) Number() protoreflect.EnumNumber {\n\treturn protoreflect.EnumNumber(x)\n}\n\n// Dep", "middle": "ring]int32{\n\t\t\"X\": 17,\n\t}\n)\n\nfunc (x FOO) Enum() *FOO {\n\tp := new(FOO)\n\t*p = x\n\treturn p\n}\n\nfunc (x FOO) String() string {\n\treturn protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))\n}\n\nfunc (FOO) Descriptor() pr", "meta": {"filepath": "testdata/protoexample/test.pb.go", "language": "go", "file_size": 8374, "cut_index": 716, "middle_length": 229}} {"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"encoding/base64\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc TestBasicAuth(t *testing.T) {\n\tpairs := processAccounts(Accounts{\n\t\t\"admin\": \"password\",\n\t\t\"foo\": \"bar\",\n\t\t\"bar\": \"foo\",\n\t})\n\n\tassert.Len(t, pairs, 3)\n\tassert.Contains(t, pairs, authPair{\n\t\tuser: \"bar\",\n\t\tvalue: \"Basic YmFyOmZvbw==\",\n\t})\n\tassert.Contains(t, pairs, authPair{\n\t\tuser: \"foo\",\n\t\tvalue: \"Basic Zm9", "suffix": "c() {\n\t\tprocessAccounts(Accounts{\n\t\t\t\"\": \"password\",\n\t\t\t\"foo\": \"bar\",\n\t\t})\n\t})\n}\n\nfunc TestBasicAuthSearchCredential(t *testing.T) {\n\tpairs := processAccounts(Accounts{\n\t\t\"admin\": \"password\",\n\t\t\"foo\": \"bar\",\n\t\t\"bar\": \"foo\",\n\t})\n\n\tuser, found := pair", "middle": "vOmJhcg==\",\n\t})\n\tassert.Contains(t, pairs, authPair{\n\t\tuser: \"admin\",\n\t\tvalue: \"Basic YWRtaW46cGFzc3dvcmQ=\",\n\t})\n}\n\nfunc TestBasicAuthFails(t *testing.T) {\n\tassert.Panics(t, func() { processAccounts(nil) })\n\tassert.Panics(t, fun", "meta": {"filepath": "auth_test.go", "language": "go", "file_size": 5074, "cut_index": 614, "middle_length": 229}} {"prefix": "writermem responseWriter\n\tRequest *http.Request\n\tWriter ResponseWriter\n\n\tParams Params\n\thandlers HandlersChain\n\tindex int8\n\tfullPath string\n\n\tengine *Engine\n\tparams *Params\n\tskippedNodes *[]skippedNode\n\n\t// This mutex protects Keys map.\n\tmu sync.RWMutex\n\n\t// Keys is a key/value pair exclusively for the context of each request.\n\tKeys map[any]any\n\n\t// Errors is a list of errors attached to all the handlers/middlewares who used this context.\n\tErrors errorMsgs\n\n\t// Accepted defines a list ", "suffix": "ed form data from POST, PATCH,\n\t// or PUT body parameters.\n\tformCache url.Values\n\n\t// SameSite allows a server to define a cookie attribute making it impossible for\n\t// the browser to send this cookie along with cross-site requests.\n\tsameSite http.SameSite", "middle": "of manually accepted formats for content negotiation.\n\tAccepted []string\n\n\t// queryCache caches the query result from c.Request.URL.Query().\n\tqueryCache url.Values\n\n\t// formCache caches c.Request.PostForm, which contains the pars", "meta": {"filepath": "context.go", "language": "go", "file_size": 46437, "cut_index": 2151, "middle_length": 229}} {"prefix": "fy/assert\"\n)\n\n// TestContextFileSimple tests the Context.File() method with a simple case\nfunc TestContextFileSimple(t *testing.T) {\n\t// Test serving an existing file\n\ttestFile := \"testdata/test_file.txt\"\n\tw := httptest.NewRecorder()\n\tc, _ := CreateTestContext(w)\n\tc.Request = httptest.NewRequest(http.MethodGet, \"/test\", nil)\n\n\tc.File(testFile)\n\n\tassert.Equal(t, http.StatusOK, w.Code)\n\tassert.Contains(t, w.Body.String(), \"This is a test file\")\n\tassert.Equal(t, \"text/plain; charset=utf-8\", w.Header().Get(\"Con", "suffix": "ving a non-existent file\nfunc TestContextFileNotFound(t *testing.T) {\n\tw := httptest.NewRecorder()\n\tc, _ := CreateTestContext(w)\n\tc.Request = httptest.NewRequest(http.MethodGet, \"/test\", nil)\n\n\tc.File(\"non_existent_file.txt\")\n\n\tassert.Equal(t, http.StatusN", "middle": "tent-Type\"))\n}\n\n// TestContextFileNotFound tests ser", "meta": {"filepath": "context_file_test.go", "language": "go", "file_size": 933, "cut_index": 606, "middle_length": 52}} {"prefix": " reserved.\n// Use of this source code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"fmt\"\n\t\"html/template\"\n\t\"runtime\"\n\t\"strconv\"\n\t\"strings\"\n\t\"sync/atomic\"\n)\n\nconst ginSupportMinGoVer = 25\n\nvar runtimeVersion = runtime.Version()\n\n// IsDebugging returns true if the framework is running in debug mode.\n// Use SetMode(gin.ReleaseMode) to disable debug mode.\nfunc IsDebugging() bool {\n\treturn atomic.LoadInt32(&ginMode) == debugCode\n}\n\n// DebugPrintRouteFunc in", "suffix": "y)\n\nfunc debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {\n\tif IsDebugging() {\n\t\tnuHandlers := len(handlers)\n\t\thandlerName := nameOfFunction(handlers.Last())\n\t\tif DebugPrintRouteFunc == nil {\n\t\t\tdebugPrint(\"%-6s %-25s --> %s (%d ha", "middle": "dicates debug log output format.\nvar DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)\n\n// DebugPrintFunc indicates debug log output format.\nvar DebugPrintFunc func(format string, values ...an", "meta": {"filepath": "debug.go", "language": "go", "file_size": 3000, "cut_index": 563, "middle_length": 229}} {"prefix": "\"\n\t\"html/template\"\n\t\"io\"\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n\t\"strings\"\n\t\"sync\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\nfunc TestIsDebugging(t *testing.T) {\n\tSetMode(DebugMode)\n\tassert.True(t, IsDebugging())\n\tSetMode(ReleaseMode)\n\tassert.False(t, IsDebugging())\n\tSetMode(TestMode)\n\tassert.False(t, IsDebugging())\n}\n\nfunc TestDebugPrint(t *testing.T) {\n\tre := captureOutput(t, func() {\n\t\tSetMode(DebugMode)\n\t\tSetMode(ReleaseMode)\n\t\tdebugPrint(\"DEBUG this!\")\n\t\tSetMode(Test", "suffix": "sting.T) {\n\tDebugPrintFunc = func(format string, values ...any) {\n\t\tfmt.Fprintf(DefaultWriter, \"[GIN-debug] \"+format, values...)\n\t}\n\tre := captureOutput(t, func() {\n\t\tSetMode(DebugMode)\n\t\tdebugPrint(\"debug print func test: %d\", 123)\n\t\tSetMode(TestMode)\n\t})", "middle": "Mode)\n\t\tdebugPrint(\"DEBUG this!\")\n\t\tSetMode(DebugMode)\n\t\tdebugPrint(\"these are %d %s\", 2, \"error messages\")\n\t\tSetMode(TestMode)\n\t})\n\tassert.Equal(t, \"[GIN-debug] these are 2 error messages\\n\", re)\n}\n\nfunc TestDebugPrintFunc(t *te", "meta": {"filepath": "debug_test.go", "language": "go", "file_size": 5413, "cut_index": 716, "middle_length": 229}} {"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"testing\"\n\n\t\"github.com/gin-gonic/gin/codec/json\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\nfunc TestError(t *testing.T) {\n\tbaseError := errors.New(\"test error\")\n\terr := &Error{\n\t\tErr: baseError,\n\t\tType: ErrorTypePrivate,\n\t}\n\tassert.Equal(t, err.Error(), baseError.Error())\n\tassert.Equal(t, H{\"error\": baseError.Error()}, err.JSON())\n\n\tassert.Equal(t, err.SetType(Erro", "suffix": " err.JSON())\n\n\tjsonBytes, _ := json.API.Marshal(err)\n\tassert.JSONEq(t, \"{\\\"error\\\":\\\"test error\\\",\\\"meta\\\":\\\"some data\\\"}\", string(jsonBytes))\n\n\terr.SetMeta(H{ //nolint: errcheck\n\t\t\"status\": \"200\",\n\t\t\"data\": \"some data\",\n\t})\n\tassert.Equal(t, H{\n\t\t\"error\"", "middle": "rTypePublic), err)\n\tassert.Equal(t, ErrorTypePublic, err.Type)\n\n\tassert.Equal(t, err.SetMeta(\"some data\"), err)\n\tassert.Equal(t, \"some data\", err.Meta)\n\tassert.Equal(t, H{\n\t\t\"error\": baseError.Error(),\n\t\t\"meta\": \"some data\",\n\t},", "meta": {"filepath": "errors_test.go", "language": "go", "file_size": 4297, "cut_index": 614, "middle_length": 229}} {"prefix": "\nimport (\n\t\"errors\"\n\t\"net/http\"\n\t\"os\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\ntype mockFileSystem struct {\n\topen func(name string) (http.File, error)\n}\n\nfunc (m *mockFileSystem) Open(name string) (http.File, error) {\n\treturn m.open(name)\n}\n\nfunc TestOnlyFilesFS_Open(t *testing.T) {\n\tvar testFile *os.File\n\tmockFS := &mockFileSystem{\n\t\topen: func(name string) (http.File, error) {\n\t\t\treturn testFile, nil\n\t\t},\n\t}\n\tfs := &OnlyFilesFS{FileSystem: mockFS}\n\n\tfile,", "suffix": " func(_ string) (http.File, error) {\n\t\t\treturn nil, testError\n\t\t},\n\t}\n\tfs := &OnlyFilesFS{FileSystem: mockFS}\n\n\tfile, err := fs.Open(\"foo\")\n\n\trequire.ErrorIs(t, err, testError)\n\tassert.Nil(t, file)\n}\n\nfunc Test_neuteredReaddirFile_Readdir(t *testing.T) {\n\t", "middle": " err := fs.Open(\"foo\")\n\n\trequire.NoError(t, err)\n\tassert.Equal(t, testFile, file.(neutralizedReaddirFile).File)\n}\n\nfunc TestOnlyFilesFS_Open_err(t *testing.T) {\n\ttestError := errors.New(\"mock\")\n\tmockFS := &mockFileSystem{\n\t\topen:", "meta": {"filepath": "fs_test.go", "language": "go", "file_size": 1395, "cut_index": 524, "middle_length": 229}} {"prefix": " 2017 Manu Martinez-Almeida. All rights reserved.\n// Use of this source code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\npackage gin\n\nimport (\n\t\"net/http\"\n\t\"os\"\n)\n\n// OnlyFilesFS implements an http.FileSystem without `Readdir` functionality.\ntype OnlyFilesFS struct {\n\tFileSystem http.FileSystem\n}\n\n// Open passes `Open` to the upstream implementation without `Readdir` functionality.\nfunc (o OnlyFilesFS) Open(name string) (http.File, error) {\n\tf, err := o.FileSystem.Open(name", "suffix": "ir overrides the http.File default implementation and always returns nil.\nfunc (n neutralizedReaddirFile) Readdir(_ int) ([]os.FileInfo, error) {\n\t// this disables directory listing\n\treturn nil, nil\n}\n\n// Dir returns an http.FileSystem that can be used by ", "middle": ")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn neutralizedReaddirFile{f}, nil\n}\n\n// neutralizedReaddirFile wraps http.File with a specific implementation of `Readdir`.\ntype neutralizedReaddirFile struct {\n\thttp.File\n}\n\n// Readd", "meta": {"filepath": "fs.go", "language": "go", "file_size": 1396, "cut_index": 524, "middle_length": 229}} {"prefix": " // 0.0.0.0/0 (IPv4)\n\t\tIP: net.IP{0x0, 0x0, 0x0, 0x0},\n\t\tMask: net.IPMask{0x0, 0x0, 0x0, 0x0},\n\t},\n\t{ // ::/0 (IPv6)\n\t\tIP: net.IP{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\tMask: net.IPMask{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t},\n}\n\n// HandlerFunc defines the handler used by gin middleware as return value.\ntype HandlerFunc func(*Context)\n\n// OptionFunc defines the function to change the default configuration\ntype Option", "suffix": "\n\tif length := len(c); length > 0 {\n\t\treturn c[length-1]\n\t}\n\treturn nil\n}\n\n// RouteInfo represents a request route's specification which contains method and path and its handler.\ntype RouteInfo struct {\n\tMethod string\n\tPath string\n\tHandler ", "middle": "Func func(*Engine)\n\n// HandlersChain defines a HandlerFunc slice.\ntype HandlersChain []HandlerFunc\n\n// Last returns the last handler in the chain. i.e. the last handler is the main one.\nfunc (c HandlersChain) Last() HandlerFunc {", "meta": {"filepath": "gin.go", "language": "go", "file_size": 27227, "cut_index": 1331, "middle_length": 229}} {"prefix": "/:access_token\"},\n\t{http.MethodDelete, \"/applications/:client_id/tokens\"},\n\t{http.MethodDelete, \"/applications/:client_id/tokens/:access_token\"},\n\n\t// Activity\n\t{http.MethodGet, \"/events\"},\n\t{http.MethodGet, \"/repos/:owner/:repo/events\"},\n\t{http.MethodGet, \"/networks/:owner/:repo/events\"},\n\t{http.MethodGet, \"/orgs/:org/events\"},\n\t{http.MethodGet, \"/users/:user/received_events\"},\n\t{http.MethodGet, \"/users/:user/received_events/public\"},\n\t{http.MethodGet, \"/users/:user/events\"},\n\t{http.MethodGet, \"/users/:use", "suffix": "\n\t{http.MethodPut, \"/repos/:owner/:repo/notifications\"},\n\t{http.MethodGet, \"/notifications/threads/:id\"},\n\t//{http.MethodPatch, \"/notifications/threads/:id\"},\n\t{http.MethodGet, \"/notifications/threads/:id/subscription\"},\n\t{http.MethodPut, \"/notifications/t", "middle": "r/events/public\"},\n\t{http.MethodGet, \"/users/:user/events/orgs/:org\"},\n\t{http.MethodGet, \"/feeds\"},\n\t{http.MethodGet, \"/notifications\"},\n\t{http.MethodGet, \"/repos/:owner/:repo/notifications\"},\n\t{http.MethodPut, \"/notifications\"},", "meta": {"filepath": "githubapi_test.go", "language": "go", "file_size": 17383, "cut_index": 1331, "middle_length": 229}} {"prefix": "outer.Use(LoggerWithWriter(buffer))\n\trouter.GET(\"/example\", func(c *Context) {})\n\trouter.POST(\"/example\", func(c *Context) {})\n\trouter.PUT(\"/example\", func(c *Context) {})\n\trouter.DELETE(\"/example\", func(c *Context) {})\n\trouter.PATCH(\"/example\", func(c *Context) {})\n\trouter.HEAD(\"/example\", func(c *Context) {})\n\trouter.OPTIONS(\"/example\", func(c *Context) {})\n\n\tPerformRequest(router, http.MethodGet, \"/example?a=100\")\n\tassert.Contains(t, buffer.String(), \"200\")\n\tassert.Contains(t, buffer.String(), http.Metho", "suffix": "whole logging process rather\n\t// than individual functions. I'm not sure where these should go.\n\tbuffer.Reset()\n\tPerformRequest(router, http.MethodPost, \"/example\")\n\tassert.Contains(t, buffer.String(), \"200\")\n\tassert.Contains(t, buffer.String(), http.Metho", "middle": "dGet)\n\tassert.Contains(t, buffer.String(), \"/example\")\n\tassert.Contains(t, buffer.String(), \"a=100\")\n\n\t// I wrote these first (extending the above) but then realized they are more\n\t// like integration tests because they test the ", "meta": {"filepath": "logger_test.go", "language": "go", "file_size": 15933, "cut_index": 921, "middle_length": 229}} {"prefix": "net/http\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/mattn/go-isatty\"\n)\n\ntype consoleColorModeValue int\n\nconst (\n\tautoColor consoleColorModeValue = iota\n\tdisableColor\n\tforceColor\n)\n\nconst (\n\tgreen = \"\\033[97;42m\"\n\twhite = \"\\033[90;47m\"\n\tyellow = \"\\033[90;43m\"\n\tred = \"\\033[97;41m\"\n\tblue = \"\\033[97;44m\"\n\tmagenta = \"\\033[97;45m\"\n\tcyan = \"\\033[97;46m\"\n\treset = \"\\033[0m\"\n)\n\nvar consoleColorMode = autoColor\n\n// LoggerConfig defines the config for Logger middleware.\ntype LoggerConfig struct {\n\t// Optional. Defau", "suffix": " written.\n\t// Optional.\n\tSkipPaths []string\n\n\t// SkipQueryString indicates that query strings should not be written\n\t// for cases such as when API keys are passed via query strings.\n\t// Optional. Default value is false.\n\tSkipQueryString bool\n\n\t// Skip is a", "middle": "lt value is gin.defaultLogFormatter\n\tFormatter LogFormatter\n\n\t// Output is a writer where logs are written.\n\t// Optional. Default value is gin.DefaultWriter.\n\tOutput io.Writer\n\n\t// SkipPaths is a URL path array which logs are not", "meta": {"filepath": "logger.go", "language": "go", "file_size": 8070, "cut_index": 716, "middle_length": 229}} {"prefix": ".SetFuncMap(template.FuncMap{\n\t\t\t\"formatAsDate\": formatAsDate,\n\t\t})\n\t\tloadMethod(router)\n\t\trouter.GET(\"/test\", func(c *Context) {\n\t\t\tc.HTML(http.StatusOK, \"hello.tmpl\", map[string]string{\"name\": \"world\"})\n\t\t})\n\t\trouter.GET(\"/raw\", func(c *Context) {\n\t\t\tc.HTML(http.StatusOK, \"raw.tmpl\", map[string]any{\n\t\t\t\t\"now\": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC), //nolint:gofumpt\n\t\t\t})\n\t\t})\n\t})\n\n\tvar ts *httptest.Server\n\n\tif tls {\n\t\tts = httptest.NewTLSServer(router)\n\t} else {\n\t\tts = httptest.NewServer(router)\n\t", "suffix": "tp.Get(ts.URL + \"/test\")\n\tif err != nil {\n\t\tt.Error(err)\n\t}\n\n\tresp, _ := io.ReadAll(res.Body)\n\tassert.Equal(t, \"