fim / fim_gin.jsonl
tomngdev's picture
Upload folder using huggingface_hub
16356ef verified
{"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, \"<h1>Hello world</h1>\", string(resp))\n}\n\nfunc TestH2c(t *testing.T) {\n\tln, err := net.Listen(\"tcp\", localhostIP+\":0\")\n\tif err != nil {\n\t\tt.Error(", "middle": "}\n\n\treturn ts\n}\n\nfunc TestLoadHTMLGlobDebugMode(t *testing.T) {\n\tts := setupHTMLFiles(\n\t\tt,\n\t\tDebugMode,\n\t\tfalse,\n\t\tfunc(router *Engine) {\n\t\t\trouter.LoadHTMLGlob(\"./testdata/template/*\")\n\t\t},\n\t)\n\tdefer ts.Close()\n\n\tres, err := ht", "meta": {"filepath": "gin_test.go", "language": "go", "file_size": 28333, "cut_index": 1331, "middle_length": 229}}
{"prefix": "rtinez-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\"os\"\n\t\"sync/atomic\"\n\t\"testing\"\n\n\t\"github.com/gin-gonic/gin/binding\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc init() {\n\tos.Setenv(EnvGinMode, TestMode)\n}\n\nfunc TestSetMode(t *testing.T) {\n\tassert.Equal(t, int32(testCode), atomic.LoadInt32(&ginMode))\n\tassert.Equal(t, TestMode, Mode())\n\tos.Unsetenv(EnvGinMode)\n\n\tSetMode(\"\")\n\tassert.Equal(t, in", "suffix": "Equal(t, int32(releaseCode), atomic.LoadInt32(&ginMode))\n\tassert.Equal(t, ReleaseMode, Mode())\n\n\tSetMode(TestMode)\n\tassert.Equal(t, int32(testCode), atomic.LoadInt32(&ginMode))\n\tassert.Equal(t, TestMode, Mode())\n\n\tassert.Panics(t, func() { SetMode(\"unknown", "middle": "t32(testCode), atomic.LoadInt32(&ginMode))\n\tassert.Equal(t, TestMode, Mode())\n\n\tSetMode(DebugMode)\n\tassert.Equal(t, int32(debugCode), atomic.LoadInt32(&ginMode))\n\tassert.Equal(t, DebugMode, Mode())\n\n\tSetMode(ReleaseMode)\n\tassert.", "meta": {"filepath": "mode_test.go", "language": "go", "file_size": 1635, "cut_index": 537, "middle_length": 229}}
{"prefix": "e Go Authors.\n// Use of this source code is governed by a BSD-style license that can be found\n// at https://github.com/julienschmidt/httprouter/blob/master/LICENSE.\n\npackage gin\n\nconst stackBufSize = 128\n\n// cleanPath is the URL version of path.Clean, it returns a canonical URL path\n// for p, eliminating . and .. elements.\n//\n// The following rules are applied iteratively until no further processing can\n// be done:\n// 1. Replace multiple slashes with a single slash.\n// 2. Eliminate each . path name elemen", "suffix": "ace \"/..\" by \"/\" at the beginning of a path.\n//\n// If the result of this process is an empty string, \"/\" is returned.\nfunc cleanPath(p string) string {\n\t// Turn empty string into \"/\"\n\tif p == \"\" {\n\t\treturn \"/\"\n\t}\n\n\t// Reasonably sized buffer on stack to av", "middle": "t (the current directory).\n// 3. Eliminate each inner .. path name element (the parent directory)\n// along with the non-.. element that precedes it.\n// 4. Eliminate .. elements that begin a rooted path:\n// that is, repl", "meta": {"filepath": "path.go", "language": "go", "file_size": 4911, "cut_index": 614, "middle_length": 229}}
{"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\"flag\"\n\t\"io\"\n\t\"os\"\n\t\"sync/atomic\"\n\n\t\"github.com/gin-gonic/gin/binding\"\n)\n\n// EnvGinMode indicates environment name for gin mode.\nconst EnvGinMode = \"GIN_MODE\"\n\nconst (\n\t// DebugMode indicates gin mode is debug.\n\tDebugMode = \"debug\"\n\t// ReleaseMode indicates gin mode is release.\n\tReleaseMode = \"release\"\n\t// TestMode indicates gin mode is test.\n\tTestMode = \"test\"\n)\n\nconst ", "suffix": " to configure their\n// output io.Writer.\n// To support coloring in Windows use:\n//\n//\timport \"github.com/mattn/go-colorable\"\n//\tgin.DefaultWriter = colorable.NewColorableStdout()\nvar DefaultWriter io.Writer = os.Stdout\n\n// DefaultErrorWriter is the default", "middle": "(\n\tdebugCode = iota\n\treleaseCode\n\ttestCode\n)\n\n// DefaultWriter is the default io.Writer used by Gin for debug output and\n// middleware output like Logger() or Recovery().\n// Note that both Logger and Recovery provides custom ways", "meta": {"filepath": "mode.go", "language": "go", "file_size": 2456, "cut_index": 563, "middle_length": 229}}
{"prefix": "s\"\n\t\"cmp\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"net/http\"\n\t\"net/http/httputil\"\n\t\"os\"\n\t\"runtime\"\n\t\"strings\"\n\t\"syscall\"\n\t\"time\"\n\n\t\"github.com/gin-gonic/gin/internal/bytesconv\"\n)\n\nconst (\n\tdunno = \"???\"\n\tstackSkip = 3\n)\n\n// RecoveryFunc defines the function passable to CustomRecovery.\ntype RecoveryFunc func(c *Context, err any)\n\n// Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.\nfunc Recovery() HandlerFunc {\n\treturn RecoveryWithWriter(DefaultErrorWriter)\n}\n\n// Custo", "suffix": "overyWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.\nfunc RecoveryWithWriter(out io.Writer, recovery ...RecoveryFunc) HandlerFunc {\n\tif len(recovery) > 0 {\n\t\treturn CustomRecoveryWithWrite", "middle": "mRecovery returns a middleware that recovers from any panics and calls the provided handle func to handle it.\nfunc CustomRecovery(handle RecoveryFunc) HandlerFunc {\n\treturn RecoveryWithWriter(DefaultErrorWriter, handle)\n}\n\n// Rec", "meta": {"filepath": "recovery.go", "language": "go", "file_size": 5720, "cut_index": 716, "middle_length": 229}}
{"prefix": "e Go Authors.\n// Use of this source code is governed by a BSD-style license that can be found\n// at https://github.com/julienschmidt/httprouter/blob/master/LICENSE\n\npackage gin\n\nimport (\n\t\"runtime\"\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n)\n\ntype cleanPathTest struct {\n\tpath, result string\n}\n\nvar cleanTests = []cleanPathTest{\n\t// Already clean\n\t{\"/\", \"/\"},\n\t{\"/abc\", \"/abc\"},\n\t{\"/a/b/c\", \"/a/b/c\"},\n\t{\"/abc/\", \"/abc/\"},\n\t{\"/a/b/c/\", \"/a/b/c/\"},\n\n\t// missing root\n\t{\"\", \"/\"},\n\t{\"a/\", \"/a/\"},", "suffix": "c\", \"/abc\"},\n\t{\"///abc\", \"/abc\"},\n\t{\"//abc//\", \"/abc/\"},\n\n\t// Remove . elements\n\t{\".\", \"/\"},\n\t{\"./\", \"/\"},\n\t{\"/abc/./def\", \"/abc/def\"},\n\t{\"/./abc/def\", \"/abc/def\"},\n\t{\"/abc/.\", \"/abc/\"},\n\n\t// Remove .. elements\n\t{\"..\", \"/\"},\n\t{\"../\", \"/\"},\n\t{\"../../\", \"/\"}", "middle": "\n\t{\"abc\", \"/abc\"},\n\t{\"abc/def\", \"/abc/def\"},\n\t{\"a/b/c\", \"/a/b/c\"},\n\n\t// Remove doubled slash\n\t{\"//\", \"/\"},\n\t{\"/abc//\", \"/abc/\"},\n\t{\"/abc/def//\", \"/abc/def/\"},\n\t{\"/a/b/c//\", \"/a/b/c/\"},\n\t{\"/abc//def//ghi\", \"/abc/def/ghi\"},\n\t{\"//ab", "meta": {"filepath": "path_test.go", "language": "go", "file_size": 3726, "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\"bufio\"\n\t\"errors\"\n\t\"io\"\n\t\"net\"\n\t\"net/http\"\n)\n\nconst (\n\tnoWritten = -1\n\tdefaultStatus = http.StatusOK\n)\n\nvar errHijackAlreadyWritten = errors.New(\"gin: response body already written\")\n\n// ResponseWriter ...\ntype ResponseWriter interface {\n\thttp.ResponseWriter\n\thttp.Hijacker\n\thttp.Flusher\n\thttp.CloseNotifier\n\n\t// Status returns the HTTP response status code of the current request.\n\tStatus() int\n\n\t// Size returns the nu", "suffix": "was already written.\n\tWritten() bool\n\n\t// WriteHeaderNow forces to write the http header (status code + headers).\n\tWriteHeaderNow()\n\n\t// Pusher get the http.Pusher for server push\n\tPusher() http.Pusher\n}\n\ntype responseWriter struct {\n\thttp.ResponseWriter\n\t", "middle": "mber of bytes already written into the response http body.\n\t// See Written()\n\tSize() int\n\n\t// WriteString writes the string into the response body.\n\tWriteString(string) (int, error)\n\n\t// Written returns true if the response body ", "meta": {"filepath": "response_writer.go", "language": "go", "file_size": 3263, "cut_index": 614, "middle_length": 229}}
{"prefix": "ng{\n\t\thttp.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch,\n\t\thttp.MethodHead, http.MethodOptions, http.MethodDelete, http.MethodConnect,\n\t\thttp.MethodTrace,\n\t}\n)\n\n// IRouter defines all router handle interface includes single and group router.\ntype IRouter interface {\n\tIRoutes\n\tGroup(string, ...HandlerFunc) *RouterGroup\n}\n\n// IRoutes defines all router handle interface.\ntype IRoutes interface {\n\tUse(...HandlerFunc) IRoutes\n\n\tHandle(string, string, ...HandlerFunc) IRoutes\n\tAny(string, ...Handle", "suffix": "dlerFunc) IRoutes\n\tHEAD(string, ...HandlerFunc) IRoutes\n\tMatch([]string, string, ...HandlerFunc) IRoutes\n\n\tStaticFile(string, string) IRoutes\n\tStaticFileFS(string, string, http.FileSystem) IRoutes\n\tStatic(string, string) IRoutes\n\tStaticFS(string, http.File", "middle": "rFunc) IRoutes\n\tGET(string, ...HandlerFunc) IRoutes\n\tPOST(string, ...HandlerFunc) IRoutes\n\tDELETE(string, ...HandlerFunc) IRoutes\n\tPATCH(string, ...HandlerFunc) IRoutes\n\tPUT(string, ...HandlerFunc) IRoutes\n\tOPTIONS(string, ...Han", "meta": {"filepath": "routergroup.go", "language": "go", "file_size": 9279, "cut_index": 921, "middle_length": 229}}
{"prefix": "esting\"\n\n\t\"github.com/stretchr/testify/assert\"\n)\n\nvar MaxHandlers = 32\n\nfunc init() {\n\tSetMode(TestMode)\n}\n\nfunc TestRouterGroupBasic(t *testing.T) {\n\trouter := New()\n\tgroup := router.Group(\"/hola\", func(c *Context) {})\n\tgroup.Use(func(c *Context) {})\n\n\tassert.Len(t, group.Handlers, 2)\n\tassert.Equal(t, \"/hola\", group.BasePath())\n\tassert.Equal(t, router, group.engine)\n\n\tgroup2 := group.Group(\"manu\")\n\tgroup2.Use(func(c *Context) {}, func(c *Context) {})\n\n\tassert.Len(t, group2.Handlers, 4)\n\tassert.Equal(t, \"/h", "suffix": "t, http.MethodPut)\n\tperformRequestInGroup(t, http.MethodPatch)\n\tperformRequestInGroup(t, http.MethodDelete)\n\tperformRequestInGroup(t, http.MethodHead)\n\tperformRequestInGroup(t, http.MethodOptions)\n}\n\nfunc performRequestInGroup(t *testing.T, method string) ", "middle": "ola/manu\", group2.BasePath())\n\tassert.Equal(t, router, group2.engine)\n}\n\nfunc TestRouterGroupBasicHandle(t *testing.T) {\n\tperformRequestInGroup(t, http.MethodGet)\n\tperformRequestInGroup(t, http.MethodPost)\n\tperformRequestInGroup(", "meta": {"filepath": "routergroup_test.go", "language": "go", "file_size": 5970, "cut_index": 716, "middle_length": 229}}
{"prefix": "ny(\"/test2\", func(c *Context) {\n\t\tpassedAny = true\n\t})\n\tr.Handle(method, \"/test\", func(c *Context) {\n\t\tpassed = true\n\t})\n\n\tw := PerformRequest(r, method, \"/test\")\n\tassert.True(t, passed)\n\tassert.Equal(t, http.StatusOK, w.Code)\n\n\tPerformRequest(r, method, \"/test2\")\n\tassert.True(t, passedAny)\n}\n\n// TestSingleRouteOK tests that POST route is correctly invoked.\nfunc testRouteNotOK(method string, t *testing.T) {\n\tpassed := false\n\trouter := New()\n\trouter.Handle(method, \"/test_2\", func(c *Context) {\n\t\tpassed = tru", "suffix": "t *testing.T) {\n\tpassed := false\n\trouter := New()\n\trouter.HandleMethodNotAllowed = true\n\tvar methodRoute string\n\tif method == http.MethodPost {\n\t\tmethodRoute = http.MethodGet\n\t} else {\n\t\tmethodRoute = http.MethodPost\n\t}\n\trouter.Handle(methodRoute, \"/test\",", "middle": "e\n\t})\n\n\tw := PerformRequest(router, method, \"/test\")\n\n\tassert.False(t, passed)\n\tassert.Equal(t, http.StatusNotFound, w.Code)\n}\n\n// TestSingleRouteOK tests that POST route is correctly invoked.\nfunc testRouteNotOK2(method string, ", "meta": {"filepath": "routes_test.go", "language": "go", "file_size": 24774, "cut_index": 1331, "middle_length": 229}}
{"prefix": "rtinez-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\"fmt\"\n\t\"net/http\"\n\t\"time\"\n)\n\n// CreateTestContext returns a fresh Engine and a Context associated with it.\n// This is useful for tests that need to set up a new Gin engine instance\n// along with a context, for example, to test middleware that doesn't depend on\n// specific routes. The ResponseWriter `w` is used to initialize the context's writer.", "suffix": "ed Engine `r`.\n// This is useful for tests that operate on an existing, possibly pre-configured,\n// Gin engine instance and need a new context for it.\n// The ResponseWriter `w` is used to initialize the context's writer.\n// The context is allocated with th", "middle": "\nfunc CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {\n\tr = New()\n\tc = r.allocateContext(0)\n\tc.reset()\n\tc.writermem.reset(w)\n\treturn\n}\n\n// CreateTestContextOnly returns a fresh Context associated with the provid", "meta": {"filepath": "test_helpers.go", "language": "go", "file_size": 1902, "cut_index": 537, "middle_length": 229}}
{"prefix": "r) {\n// func (w *responseWriter) CloseNotify() <-chan bool {\n// func (w *responseWriter) Flush() {\n\nvar (\n\t_ ResponseWriter = &responseWriter{}\n\t_ http.ResponseWriter = &responseWriter{}\n\t_ http.ResponseWriter = ResponseWriter(&responseWriter{})\n\t_ http.Hijacker = ResponseWriter(&responseWriter{})\n\t_ http.Flusher = ResponseWriter(&responseWriter{})\n\t_ http.CloseNotifier = ResponseWriter(&responseWriter{})\n)\n\nfunc init() {\n\tSetMode(TestMode)\n}\n\nfunc TestResponseWriterUnwrap(t *testing.T) {", "suffix": "ter := &responseWriter{}\n\tvar w ResponseWriter = writer\n\n\twriter.reset(testWriter)\n\tassert.Equal(t, -1, writer.size)\n\tassert.Equal(t, http.StatusOK, writer.status)\n\tassert.Equal(t, testWriter, writer.ResponseWriter)\n\tassert.Equal(t, -1, w.Size())\n\tassert.E", "middle": "\n\ttestWriter := httptest.NewRecorder()\n\twriter := &responseWriter{ResponseWriter: testWriter}\n\tassert.Same(t, testWriter, writer.Unwrap())\n}\n\nfunc TestResponseWriterReset(t *testing.T) {\n\ttestWriter := httptest.NewRecorder()\n\twri", "meta": {"filepath": "response_writer_test.go", "language": "go", "file_size": 9282, "cut_index": 921, "middle_length": 229}}
{"prefix": "e '%s'\", request.path)\n\t\t\t}\n\t\t}\n\n\t}\n}\n\nfunc checkPriorities(t *testing.T, n *node) uint32 {\n\tvar prio uint32\n\tfor i := range n.children {\n\t\tprio += checkPriorities(t, n.children[i])\n\t}\n\n\tif n.handlers != nil {\n\t\tprio++\n\t}\n\n\tif n.priority != prio {\n\t\tt.Errorf(\n\t\t\t\"priority mismatch for node '%s': is %d, should be %d\",\n\t\t\tn.path, n.priority, prio,\n\t\t)\n\t}\n\n\treturn prio\n}\n\nfunc TestCountParams(t *testing.T) {\n\tif countParams(\"/path/:param1/static/*catch-all\") != 2 {\n\t\tt.Fail()\n\t}\n\tif countParams(strings.Repeat(", "suffix": "l\",\n\t\t\"\",\n\t\t\"\",\n\t}\n\tfor _, route := range routes {\n\t\ttree.addRoute(route, fakeHandler(route))\n\t}\n\n\tcheckRequests(t, tree, testRequests{\n\t\t{\"/a\", false, \"/a\", nil},\n\t\t{\"/\", true, \"\", nil},\n\t\t{\"/hi\", false, \"/hi\", nil},\n\t\t{\"/contact\", false, \"/contact\", ", "middle": "\"/:param\", 256)) != 256 {\n\t\tt.Fail()\n\t}\n}\n\nfunc TestTreeAddAndGet(t *testing.T) {\n\ttree := &node{}\n\n\troutes := [...]string{\n\t\t\"/hi\",\n\t\t\"/contact\",\n\t\t\"/co\",\n\t\t\"/c\",\n\t\t\"/a\",\n\t\t\"/ab\",\n\t\t\"/doc/\",\n\t\t\"/doc/go_faq.html\",\n\t\t\"/doc/go1.htm", "meta": {"filepath": "tree_test.go", "language": "go", "file_size": 35988, "cut_index": 2151, "middle_length": 229}}
{"prefix": "e\"\n\t\"net/http\"\n\t\"sync\"\n\n\t\"github.com/gin-gonic/gin\"\n)\n\nvar engine = sync.OnceValue(func() *gin.Engine {\n\treturn gin.Default()\n})\n\n// LoadHTMLGlob is a wrapper for Engine.LoadHTMLGlob.\nfunc LoadHTMLGlob(pattern string) {\n\tengine().LoadHTMLGlob(pattern)\n}\n\n// LoadHTMLFiles is a wrapper for Engine.LoadHTMLFiles.\nfunc LoadHTMLFiles(files ...string) {\n\tengine().LoadHTMLFiles(files...)\n}\n\n// LoadHTMLFS is a wrapper for Engine.LoadHTMLFS.\nfunc LoadHTMLFS(fs http.FileSystem, patterns ...string) {\n\tengine().LoadHTML", "suffix": "y default.\nfunc NoRoute(handlers ...gin.HandlerFunc) {\n\tengine().NoRoute(handlers...)\n}\n\n// NoMethod is a wrapper for Engine.NoMethod.\nfunc NoMethod(handlers ...gin.HandlerFunc) {\n\tengine().NoMethod(handlers...)\n}\n\n// Group creates a new router group. You ", "middle": "FS(fs, patterns...)\n}\n\n// SetHTMLTemplate is a wrapper for Engine.SetHTMLTemplate.\nfunc SetHTMLTemplate(templ *template.Template) {\n\tengine().SetHTMLTemplate(templ)\n}\n\n// NoRoute adds handlers for NoRoute. It returns a 404 code b", "meta": {"filepath": "ginS/gins.go", "language": "go", "file_size": 5654, "cut_index": 716, "middle_length": 229}}
{"prefix": " Copyright 2025 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\"go.mongodb.org/mongo-driver/v2/bson\"\n)\n\n// BSON contains the given interface object.\ntype BSON struct {\n\tData any\n}\n\nvar bsonContentType = []string{\"application/bson\"}\n\n// Render (BSON) marshals the given interface object and writes data with custom ContentType.\nfunc (r BSON) Render(w http.ResponseWriter) error {\n", "suffix": "tType(w)\n\n\tbytes, err := bson.Marshal(&r.Data)\n\tif err == nil {\n\t\t_, err = w.Write(bytes)\n\t}\n\treturn err\n}\n\n// WriteContentType (BSONBuf) writes BSONBuf ContentType.\nfunc (r BSON) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, bsonContentTy", "middle": "\tr.WriteConten", "meta": {"filepath": "render/bson.go", "language": "go", "file_size": 790, "cut_index": 514, "middle_length": 14}}
{"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\npackage render\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"html/template\"\n\t\"net/http\"\n\t\"unicode\"\n\n\t\"github.com/gin-gonic/gin/codec/json\"\n\t\"github.com/gin-gonic/gin/internal/bytesconv\"\n)\n\n// JSON contains the given interface object.\ntype JSON struct {\n\tData any\n}\n\n// IndentedJSON contains the given interface object.\ntype IndentedJSON struct {\n\tData any\n}\n\n// SecureJSON contains the given interface object and its prefix.\ntype SecureJSON struct {\n\tPrefix string\n", "suffix": "eJSON contains the given interface object.\ntype PureJSON struct {\n\tData any\n}\n\nvar (\n\tjsonContentType = []string{\"application/json; charset=utf-8\"}\n\tjsonpContentType = []string{\"application/javascript; charset=utf-8\"}\n\tjsonASCIIContentType = []str", "middle": "\tData any\n}\n\n// JsonpJSON contains the given interface object its callback.\ntype JsonpJSON struct {\n\tCallback string\n\tData any\n}\n\n// AsciiJSON contains the given interface object.\ntype AsciiJSON struct {\n\tData any\n}\n\n// Pur", "meta": {"filepath": "render/json.go", "language": "go", "file_size": 5013, "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\"bytes\"\n\t\"encoding/xml\"\n\t\"fmt\"\n\t\"math\"\n\t\"net/http\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\nfunc init() {\n\tSetMode(TestMode)\n}\n\nfunc BenchmarkParseAccept(b *testing.B) {\n\tfor b.Loop() {\n\t\tparseAccept(\"text/html , application/xhtml+xml,application/xml;q=0.9, */* ;q=0.8\")\n\t}\n}\n\ntype testStruct struct {\n\tT *testing.T\n}\n\nfunc (t *testStruct) ServeHTTP(w http.ResponseWriter,", "suffix": "w()\n\trouter.POST(\"/path\", WrapH(&testStruct{t}))\n\trouter.GET(\"/path2\", WrapF(func(w http.ResponseWriter, req *http.Request) {\n\t\tassert.Equal(t, http.MethodGet, req.Method)\n\t\tassert.Equal(t, \"/path2\", req.URL.Path)\n\t\tw.WriteHeader(http.StatusBadRequest)\n\t\tf", "middle": " req *http.Request) {\n\tassert.Equal(t.T, http.MethodPost, req.Method)\n\tassert.Equal(t.T, \"/path\", req.URL.Path)\n\tw.WriteHeader(http.StatusInternalServerError)\n\tfmt.Fprint(w, \"hello\")\n}\n\nfunc TestWrap(t *testing.T) {\n\trouter := Ne", "meta": {"filepath": "utils_test.go", "language": "go", "file_size": 4604, "cut_index": 614, "middle_length": 229}}
{"prefix": "/http\"\n\t\"net/http/httptest\"\n\t\"testing\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/stretchr/testify/assert\"\n)\n\nfunc init() {\n\tgin.SetMode(gin.TestMode)\n}\n\nfunc TestGET(t *testing.T) {\n\tGET(\"/test\", func(c *gin.Context) {\n\t\tc.String(http.StatusOK, \"test\")\n\t})\n\n\treq := httptest.NewRequest(http.MethodGet, \"/test\", nil)\n\tw := httptest.NewRecorder()\n\tengine().ServeHTTP(w, req)\n\n\tassert.Equal(t, http.StatusOK, w.Code)\n\tassert.Equal(t, \"test\", w.Body.String())\n}\n\nfunc TestPOST(t *testing.T) {\n\tPOST(\"/post\", func(c *", "suffix": "rt.Equal(t, \"created\", w.Body.String())\n}\n\nfunc TestPUT(t *testing.T) {\n\tPUT(\"/put\", func(c *gin.Context) {\n\t\tc.String(http.StatusOK, \"updated\")\n\t})\n\n\treq := httptest.NewRequest(http.MethodPut, \"/put\", nil)\n\tw := httptest.NewRecorder()\n\tengine().ServeHTTP(", "middle": "gin.Context) {\n\t\tc.String(http.StatusCreated, \"created\")\n\t})\n\n\treq := httptest.NewRequest(http.MethodPost, \"/post\", nil)\n\tw := httptest.NewRecorder()\n\tengine().ServeHTTP(w, req)\n\n\tassert.Equal(t, http.StatusCreated, w.Code)\n\tasse", "meta": {"filepath": "ginS/gins_test.go", "language": "go", "file_size": 5862, "cut_index": 716, "middle_length": 229}}
{"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 render\n\nimport (\n\t\"html/template\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin/internal/fs\"\n)\n\n// Delims represents a set of Left and Right delimiters for HTML template rendering.\ntype Delims struct {\n\t// Left delimiter, defaults to {{.\n\tLeft string\n\t// Right delimiter, defaults to }}.\n\tRight string\n}\n\n// HTMLRender interface is to be implemented by HTMLProduction and HTMLDebug.\ntype HTMLRe", "suffix": "// HTMLDebug contains template delims and pattern and function with file list.\ntype HTMLDebug struct {\n\tFiles []string\n\tGlob string\n\tFileSystem http.FileSystem\n\tPatterns []string\n\tDelims Delims\n\tFuncMap template.FuncMap\n}\n\n// HTML conta", "middle": "nder interface {\n\t// Instance returns an HTML instance.\n\tInstance(string, any) Render\n}\n\n// HTMLProduction contains template reference and its delims.\ntype HTMLProduction struct {\n\tTemplate *template.Template\n\tDelims Delims\n}\n\n", "meta": {"filepath": "render/html.go", "language": "go", "file_size": 2875, "cut_index": 563, "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/xml\"\n\t\"math\"\n\t\"net/http\"\n\t\"os\"\n\t\"path\"\n\t\"reflect\"\n\t\"runtime\"\n\t\"strings\"\n\t\"unicode\"\n)\n\n// BindKey indicates a default bind key.\nconst BindKey = \"_gin-gonic/gin/bindkey\"\n\n// localhostIP indicates the default localhost IP address.\nconst localhostIP = \"127.0.0.1\"\n\n// localhostIPv6 indicates the default localhost IPv6 address.\nconst localhostIPv6 = \"::1\"\n\n// Bind is a helper function for given interface object and r", "suffix": ")\n`)\n\t}\n\ttyp := value.Type()\n\n\treturn func(c *Context) {\n\t\tobj := reflect.New(typ).Interface()\n\t\tif c.Bind(obj) == nil {\n\t\t\tc.Set(BindKey, obj)\n\t\t}\n\t}\n}\n\n// WrapF is a helper function for wrapping http.HandlerFunc and returns a Gin middleware.\nfunc WrapF(f", "middle": "eturns a Gin middleware.\nfunc Bind(val any) HandlerFunc {\n\tvalue := reflect.ValueOf(val)\n\tif value.Kind() == reflect.Ptr {\n\t\tpanic(`Bind struct can not be a pointer. Example:\n\tUse: gin.Bind(Struct{}) instead of gin.Bind(&Struct{}", "meta": {"filepath": "utils.go", "language": "go", "file_size": 4117, "cut_index": 614, "middle_length": 229}}
{"prefix": "yright 2018 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\"io\"\n\t\"net/http\"\n\t\"strconv\"\n)\n\n// Reader contains the IO reader and its length, and custom ContentType and other headers.\ntype Reader struct {\n\tContentType string\n\tContentLength int64\n\tReader io.Reader\n\tHeaders map[string]string\n}\n\n// Render (Reader) writes data with custom ContentType and headers.\nfunc (r Reader) Re", "suffix": "\tr.writeHeaders(w)\n\t_, err = io.Copy(w, r.Reader)\n\treturn\n}\n\n// WriteContentType (Reader) writes custom ContentType.\nfunc (r Reader) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, []string{r.ContentType})\n}\n\n// writeHeaders writes headers f", "middle": "nder(w http.ResponseWriter) (err error) {\n\tr.WriteContentType(w)\n\tif r.ContentLength >= 0 {\n\t\tif r.Headers == nil {\n\t\t\tr.Headers = map[string]string{}\n\t\t}\n\t\tr.Headers[\"Content-Length\"] = strconv.FormatInt(r.ContentLength, 10)\n\t}\n", "meta": {"filepath": "render/reader.go", "language": "go", "file_size": 1195, "cut_index": 518, "middle_length": 229}}
{"prefix": "eida. 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\"fmt\"\n\t\"net/http\"\n)\n\n// Redirect contains the http request reference and redirects status code and location.\ntype Redirect struct {\n\tCode int\n\tRequest *http.Request\n\tLocation string\n}\n\n// Render (Redirect) redirects the http request to new location and writes redirect response.\nfunc (r Redirect) Render(w http.ResponseWriter) error {\n\tif (r.Code < ", "suffix": "rmanentRedirect) && r.Code != http.StatusCreated {\n\t\tpanic(fmt.Sprintf(\"Cannot redirect with status code %d\", r.Code))\n\t}\n\thttp.Redirect(w, r.Request, r.Location, r.Code)\n\treturn nil\n}\n\n// WriteContentType (Redirect) don't write any ContentType.\nfunc (r Re", "middle": "http.StatusMultipleChoices || r.Code > http.StatusPe", "meta": {"filepath": "render/redirect.go", "language": "go", "file_size": 904, "cut_index": 547, "middle_length": 52}}
{"prefix": "Error(t, err)\n\tassert.JSONEq(t, \"{\\\"foo\\\":\\\"bar\\\",\\\"html\\\":\\\"\\\\u003cb\\\\u003e\\\"}\", w.Body.String())\n\tassert.Equal(t, \"application/json; charset=utf-8\", w.Header().Get(\"Content-Type\"))\n}\n\nfunc TestRenderJSONError(t *testing.T) {\n\tw := httptest.NewRecorder()\n\tdata := make(chan int)\n\n\t// json: unsupported type: chan int\n\trequire.Error(t, (JSON{data}).Render(w))\n}\n\nfunc TestRenderIndentedJSON(t *testing.T) {\n\tw := httptest.NewRecorder()\n\tdata := map[string]any{\n\t\t\"foo\": \"bar\",\n\t\t\"bar\": \"foo\",\n\t}\n\n\terr := (Indent", "suffix": " TestRenderIndentedJSONPanics(t *testing.T) {\n\tw := httptest.NewRecorder()\n\tdata := make(chan int)\n\n\t// json: unsupported type: chan int\n\terr := (IndentedJSON{data}).Render(w)\n\trequire.Error(t, err)\n}\n\nfunc TestRenderSecureJSON(t *testing.T) {\n\tw1 := httpt", "middle": "edJSON{data}).Render(w)\n\n\trequire.NoError(t, err)\n\tassert.JSONEq(t, \"{\\n \\\"bar\\\": \\\"foo\\\",\\n \\\"foo\\\": \\\"bar\\\"\\n}\", w.Body.String())\n\tassert.Equal(t, \"application/json; charset=utf-8\", w.Header().Get(\"Content-Type\"))\n}\n\nfunc", "meta": {"filepath": "render/render_test.go", "language": "go", "file_size": 20859, "cut_index": 1331, "middle_length": 229}}
{"prefix": "Copyright 2014 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 render\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin/internal/bytesconv\"\n)\n\n// String contains the given interface object slice and its format.\ntype String struct {\n\tFormat string\n\tData []any\n}\n\nvar plainContentType = []string{\"text/plain; charset=utf-8\"}\n\n// Render (String) writes data with custom ContentType.\nfunc (r String", "suffix": "tType)\n}\n\n// WriteString writes data according to its format and write custom ContentType.\nfunc WriteString(w http.ResponseWriter, format string, data []any) (err error) {\n\twriteContentType(w, plainContentType)\n\tif len(data) > 0 {\n\t\t_, err = fmt.Fprintf(w,", "middle": ") Render(w http.ResponseWriter) error {\n\treturn WriteString(w, r.Format, r.Data)\n}\n\n// WriteContentType (String) writes Plain ContentType.\nfunc (r String) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, plainConten", "meta": {"filepath": "render/text.go", "language": "go", "file_size": 1091, "cut_index": 515, "middle_length": 229}}
{"prefix": "yright 2014 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 render\n\nimport \"net/http\"\n\n// Render interface is to be implemented by JSON, XML, HTML, YAML and so on.\ntype Render interface {\n\t// Render writes data with custom ContentType.\n\tRender(http.ResponseWriter) error\n\t// WriteContentType writes custom ContentType.\n\tWriteContentType(w http.ResponseWriter)\n}\n\nvar (\n\t_ Render = (*JSON)(nil)\n\t_ Re", "suffix": "er = (*HTML)(nil)\n\t_ HTMLRender = (*HTMLDebug)(nil)\n\t_ HTMLRender = (*HTMLProduction)(nil)\n\t_ Render = (*YAML)(nil)\n\t_ Render = (*Reader)(nil)\n\t_ Render = (*AsciiJSON)(nil)\n\t_ Render = (*ProtoBuf)(nil)\n\t_ Render = (*TOML)(nil)\n\t_ Re", "middle": "nder = (*IndentedJSON)(nil)\n\t_ Render = (*SecureJSON)(nil)\n\t_ Render = (*JsonpJSON)(nil)\n\t_ Render = (*XML)(nil)\n\t_ Render = (*String)(nil)\n\t_ Render = (*Redirect)(nil)\n\t_ Render = (*Data)(nil)\n\t_ Rend", "meta": {"filepath": "render/render.go", "language": "go", "file_size": 1203, "cut_index": 518, "middle_length": 229}}
{"prefix": " 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\"google.golang.org/protobuf/proto\"\n)\n\n// ProtoBuf contains the given interface object.\ntype ProtoBuf struct {\n\tData any\n}\n\nvar protobufContentType = []string{\"application/x-protobuf\"}\n\n// Render (ProtoBuf) marshals the given interface object and writes data with custom ContentType.\nfunc (r ProtoBuf) Render(w http.ResponseWriter) ", "suffix": ".Marshal(r.Data.(proto.Message))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t_, err = w.Write(bytes)\n\treturn err\n}\n\n// WriteContentType (ProtoBuf) writes ProtoBuf ContentType.\nfunc (r ProtoBuf) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, protobuf", "middle": "error {\n\tr.WriteContentType(w)\n\n\tbytes, err := proto", "meta": {"filepath": "render/protobuf.go", "language": "go", "file_size": 852, "cut_index": 529, "middle_length": 52}}
{"prefix": "rtinez-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\"errors\"\n\t\"net/http/httptest\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n\t\"github.com/ugorji/go/codec\"\n)\n\nfunc TestRenderMsgPack(t *testing.T) {\n\tw := httptest.NewRecorder()\n\tdata := map[string]any{\n\t\t\"foo\": \"bar\",\n\t}\n\n\t(MsgPack{data}).WriteContentType(w)\n\tassert.Equal(t, \"a", "suffix": "derBytes(w.Body.Bytes(), &mh).Decode(&decoded)\n\trequire.NoError(t, err)\n\tassert.Equal(t, data, decoded)\n\tassert.Equal(t, \"application/msgpack; charset=utf-8\", w.Header().Get(\"Content-Type\"))\n}\n\nfunc TestWriteMsgPack(t *testing.T) {\n\tw := httptest.NewRecord", "middle": "pplication/msgpack; charset=utf-8\", w.Header().Get(\"Content-Type\"))\n\n\terr := (MsgPack{data}).Render(w)\n\n\trequire.NoError(t, err)\n\n\tvar decoded map[string]any\n\tvar mh codec.MsgpackHandle\n\tmh.RawToString = true\n\terr = codec.NewDeco", "meta": {"filepath": "render/render_msgpack_test.go", "language": "go", "file_size": 1902, "cut_index": 537, "middle_length": 229}}
{"prefix": "/ Copyright 2014 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 render\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/goccy/go-yaml\"\n)\n\n// YAML contains the given interface object.\ntype YAML struct {\n\tData any\n}\n\nvar yamlContentType = []string{\"application/yaml; charset=utf-8\"}\n\n// Render (YAML) marshals the given interface object and writes data with custom ContentType.\nfunc (r YAML) Render(w http.ResponseWri", "suffix": "yaml.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 (YAML) writes YAML ContentType for response.\nfunc (r YAML) WriteContentType(w http.ResponseWriter) {\n\twriteContentType(w, yamlContentType)\n}\n", "middle": "ter) error {\n\tr.WriteContentType(w)\n\n\tbytes, err := ", "meta": {"filepath": "render/yaml.go", "language": "go", "file_size": 821, "cut_index": 513, "middle_length": 52}}
{"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\n//go:build !nomsgpack\n\npackage binding\n\nimport \"net/http\"\n\n// Content-Type MIME of the most common data formats.\nconst (\n\tMIMEJSON = \"application/json\"\n\tMIMEHTML = \"text/html\"\n\tMIMEXML = \"application/xml\"\n\tMIMEXML2 = \"text/xml\"\n\tMIMEPlain = \"text/plain\"\n\tMIMEPOSTForm = \"application/x-www-form-urlencoded\"\n\tMIMEMultipartPOSTForm = \"multipart/form-data\"\n\tMIMEPROTOBUF ", "suffix": " = \"application/toml\"\n\tMIMEBSON = \"application/bson\"\n)\n\n// Binding describes the interface which needs to be implemented for binding the\n// data present in the request such as JSON request body, query parameters or\n// the form POST.\nt", "middle": " = \"application/x-protobuf\"\n\tMIMEMSGPACK = \"application/x-msgpack\"\n\tMIMEMSGPACK2 = \"application/msgpack\"\n\tMIMEYAML = \"application/x-yaml\"\n\tMIMEYAML2 = \"application/yaml\"\n\tMIMETOML ", "meta": {"filepath": "binding/binding.go", "language": "go", "file_size": 4294, "cut_index": 614, "middle_length": 229}}
{"prefix": " 2020 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\n//go:build !nomsgpack\n\npackage binding\n\nimport (\n\t\"bytes\"\n\t\"net/http\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n\t\"github.com/ugorji/go/codec\"\n)\n\nfunc TestBindingMsgPack(t *testing.T) {\n\ttest := FooStruct{\n\t\tFoo: \"bar\",\n\t}\n\n\th := new(codec.MsgpackHandle)\n\tassert.NotNil(t, h)\n\tbuf := bytes.NewBuffer([]byte{})\n\tassert.N", "suffix": "ding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {\n\tassert.Equal(t, name, b.Name())\n\n\tobj := FooStruct{}\n\treq := requestWithBody(http.MethodPost, path, body)\n\treq.Header.Add(\"Content-Type\", MIMEMSGPACK)\n\terr := b.Bind(req, &obj)\n\tre", "middle": "otNil(t, buf)\n\terr := codec.NewEncoder(buf, h).Encode(test)\n\trequire.NoError(t, err)\n\n\tdata := buf.Bytes()\n\n\ttestMsgPackBodyBinding(t,\n\t\tMsgPack, \"msgpack\",\n\t\t\"/\", \"/\",\n\t\tstring(data), string(data[1:]))\n}\n\nfunc testMsgPackBodyBin", "meta": {"filepath": "binding/binding_msgpack_test.go", "language": "go", "file_size": 1423, "cut_index": 524, "middle_length": 229}}
{"prefix": " time.Time `form:\"time_bar\" time_format:\"2006-01-02\" time_utc:\"1\"`\n\tCreateTime time.Time `form:\"createTime\" time_format:\"unixNano\"`\n\tUnixTime time.Time `form:\"unixTime\" time_format:\"unix\"`\n\tUnixMilliTime time.Time `form:\"unixMilliTime\" time_format:\"unixmilli\"`\n\tUnixMicroTime time.Time `form:\"unixMicroTime\" time_format:\"uNiXmiCrO\"`\n}\n\ntype FooStructForTimeTypeNotUnixFormat struct {\n\tCreateTime time.Time `form:\"createTime\" time_format:\"unixNano\"`\n\tUnixTime time.Time `form:\"unixTime\" time_forma", "suffix": "me_foo\"`\n}\n\ntype FooStructForTimeTypeFailFormat struct {\n\tTimeFoo time.Time `form:\"time_foo\" time_format:\"2017-11-15\"`\n}\n\ntype FooStructForTimeTypeFailLocation struct {\n\tTimeFoo time.Time `form:\"time_foo\" time_format:\"2006-01-02\" time_location:\"/asia/chong", "middle": "t:\"unix\"`\n\tUnixMilliTime time.Time `form:\"unixMilliTime\" time_format:\"unixMilli\"`\n\tUnixMicroTime time.Time `form:\"unixMicroTime\" time_format:\"unixMicro\"`\n}\n\ntype FooStructForTimeTypeNotFormat struct {\n\tTimeFoo time.Time `form:\"ti", "meta": {"filepath": "binding/binding_test.go", "language": "go", "file_size": 39518, "cut_index": 2151, "middle_length": 229}}
{"prefix": "style\n// license that can be found in the LICENSE file.\n\npackage binding\n\nimport (\n\t\"errors\"\n\t\"testing\"\n)\n\nfunc TestSliceValidationError(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\terr SliceValidationError\n\t\twant string\n\t}{\n\t\t{\"has nil elements\", SliceValidationError{errors.New(\"test error\"), nil}, \"[0]: test error\"},\n\t\t{\"has zero elements\", SliceValidationError{}, \"\"},\n\t\t{\"has one element\", SliceValidationError{errors.New(\"test one error\")}, \"[0]: test one error\"},\n\t\t{\n\t\t\t\"has two elements\",\n\t\t\tS", "suffix": "rs.New(\"second error\"),\n\t\t\t\tnil,\n\t\t\t\tnil,\n\t\t\t\tnil,\n\t\t\t\terrors.New(\"last error\"),\n\t\t\t},\n\t\t\t\"[0]: first error\\n[1]: second error\\n[5]: last error\",\n\t\t},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tif got := tt.err.Error(); got != ", "middle": "liceValidationError{\n\t\t\t\terrors.New(\"first error\"),\n\t\t\t\terrors.New(\"second error\"),\n\t\t\t},\n\t\t\t\"[0]: first error\\n[1]: second error\",\n\t\t},\n\t\t{\n\t\t\t\"has many elements\",\n\t\t\tSliceValidationError{\n\t\t\t\terrors.New(\"first error\"),\n\t\t\t\terro", "meta": {"filepath": "binding/default_validator_test.go", "language": "go", "file_size": 3591, "cut_index": 614, "middle_length": 229}}
{"prefix": " 2014 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 binding\n\nimport (\n\t\"errors\"\n\t\"net/http\"\n)\n\nconst defaultMemory = 32 << 20\n\ntype (\n\tformBinding struct{}\n\tformPostBinding struct{}\n\tformMultipartBinding struct{}\n)\n\nfunc (formBinding) Name() string {\n\treturn \"form\"\n}\n\nfunc (formBinding) Bind(req *http.Request, obj any) error {\n\tif err := req.ParseForm(); err != nil {\n\t\treturn err\n\t}\n\t", "suffix": ") Name() string {\n\treturn \"form-urlencoded\"\n}\n\nfunc (formPostBinding) Bind(req *http.Request, obj any) error {\n\tif err := req.ParseForm(); err != nil {\n\t\treturn err\n\t}\n\tif err := mapForm(obj, req.PostForm); err != nil {\n\t\treturn err\n\t}\n\treturn validate(obj", "middle": "if err := req.ParseMultipartForm(defaultMemory); err != nil && !errors.Is(err, http.ErrNotMultipart) {\n\t\treturn err\n\t}\n\tif err := mapForm(obj, req.Form); err != nil {\n\t\treturn err\n\t}\n\treturn validate(obj)\n}\n\nfunc (formPostBinding", "meta": {"filepath": "binding/form.go", "language": "go", "file_size": 1357, "cut_index": 524, "middle_length": 229}}
{"prefix": ".New(\"unknown type\")\n\n\t// ErrConvertMapStringSlice can not convert to map[string][]string\n\tErrConvertMapStringSlice = errors.New(\"can not convert to map slices of strings\")\n\n\t// ErrConvertToMapString can not convert to map[string]string\n\tErrConvertToMapString = errors.New(\"can not convert to map of strings\")\n)\n\nfunc mapURI(ptr any, m map[string][]string) error {\n\treturn mapFormByTag(ptr, m, \"uri\")\n}\n\nfunc mapForm(ptr any, form map[string][]string) error {\n\treturn mapFormByTag(ptr, form, \"form\")\n}\n\nfunc MapF", "suffix": "if ptr is a map\n\tptrVal := reflect.ValueOf(ptr)\n\tvar pointed any\n\tif ptrVal.Kind() == reflect.Ptr {\n\t\tptrVal = ptrVal.Elem()\n\t\tpointed = ptrVal.Interface()\n\t}\n\tif ptrVal.Kind() == reflect.Map &&\n\t\tptrVal.Type().Key().Kind() == reflect.String {\n\t\tif pointed", "middle": "ormWithTag(ptr any, form map[string][]string, tag string) error {\n\treturn mapFormByTag(ptr, form, tag)\n}\n\nvar emptyField = reflect.StructField{}\n\nfunc mapFormByTag(ptr any, form map[string][]string, tag string) error {\n\t// Check ", "meta": {"filepath": "binding/form_mapping.go", "language": "go", "file_size": 13602, "cut_index": 921, "middle_length": 229}}
{"prefix": "style\n// license that can be found in the LICENSE file.\n\n//go:build nomsgpack\n\npackage binding\n\nimport \"net/http\"\n\n// Content-Type MIME of the most common data formats.\nconst (\n\tMIMEJSON = \"application/json\"\n\tMIMEHTML = \"text/html\"\n\tMIMEXML = \"application/xml\"\n\tMIMEXML2 = \"text/xml\"\n\tMIMEPlain = \"text/plain\"\n\tMIMEPOSTForm = \"application/x-www-form-urlencoded\"\n\tMIMEMultipartPOSTForm = \"multipart/form-data\"\n\tMIMEPROTOBUF = \"app", "suffix": "terface which needs to be implemented for binding the\n// data present in the request such as JSON request body, query parameters or\n// the form POST.\ntype Binding interface {\n\tName() string\n\tBind(*http.Request, any) error\n}\n\n// BindingBody adds BindBody me", "middle": "lication/x-protobuf\"\n\tMIMEYAML = \"application/x-yaml\"\n\tMIMEYAML2 = \"application/yaml\"\n\tMIMETOML = \"application/toml\"\n\tMIMEBSON = \"application/bson\"\n)\n\n// Binding describes the in", "meta": {"filepath": "binding/binding_nomsgpack.go", "language": "go", "file_size": 3822, "cut_index": 614, "middle_length": 229}}
{"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 binding\n\nimport (\n\t\"reflect\"\n\t\"strconv\"\n\t\"strings\"\n\t\"sync\"\n\n\t\"github.com/go-playground/validator/v10\"\n)\n\ntype defaultValidator struct {\n\tonce sync.Once\n\tvalidate *validator.Validate\n}\n\ntype SliceValidationError []error\n\n// Error concatenates all error elements in SliceValidationError into a single string separated by \\n.\nfunc (err SliceValidationError) Error() string {\n\tif len(err)", "suffix": "ing()\n}\n\nvar _ StructValidator = (*defaultValidator)(nil)\n\n// ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.\nfunc (v *defaultValidator) ValidateStruct(obj any) error {\n\tif obj == nil {\n\t\treturn nil\n\t}\n\n\tvalue", "middle": " == 0 {\n\t\treturn \"\"\n\t}\n\n\tvar b strings.Builder\n\tfor i := range len(err) {\n\t\tif err[i] != nil {\n\t\t\tif b.Len() > 0 {\n\t\t\t\tb.WriteString(\"\\n\")\n\t\t\t}\n\t\t\tb.WriteString(\"[\" + strconv.Itoa(i) + \"]: \" + err[i].Error())\n\t\t}\n\t}\n\treturn b.Str", "meta": {"filepath": "binding/default_validator.go", "language": "go", "file_size": 2294, "cut_index": 563, "middle_length": 229}}
{"prefix": "ader }{}, \"\", &multipart.FileHeader{}},\n\t} {\n\t\ttp := reflect.TypeOf(tt.value)\n\t\ttestName := tt.name + \":\" + tp.Field(0).Type.String()\n\n\t\tval := reflect.New(reflect.TypeOf(tt.value))\n\t\tval.Elem().Set(reflect.ValueOf(tt.value))\n\n\t\tfield := val.Elem().Type().Field(0)\n\n\t\t_, err := mapping(val, emptyField, formSource{field.Name: {tt.form}}, \"form\")\n\t\trequire.NoError(t, err, testName)\n\n\t\tactual := val.Elem().Field(0).Interface()\n\t\tassert.Equal(t, tt.expect, actual, testName)\n\t}\n}\n\nfunc TestMappingDefault(t *testi", "suffix": "re.NoError(t, err)\n\n\tassert.Equal(t, \"defaultVal\", s.Str)\n\tassert.Equal(t, 9, s.Int)\n\tassert.Equal(t, []int{9}, s.Slice)\n\tassert.Equal(t, [1]int{9}, s.Array)\n}\n\nfunc TestMappingSkipField(t *testing.T) {\n\tvar s struct {\n\t\tA int\n\t}\n\terr := mappingByPtr(&s, f", "middle": "ng.T) {\n\tvar s struct {\n\t\tStr string `form:\",default=defaultVal\"`\n\t\tInt int `form:\",default=9\"`\n\t\tSlice []int `form:\",default=9\"`\n\t\tArray [1]int `form:\",default=9\"`\n\t}\n\terr := mappingByPtr(&s, formSource{}, \"form\")\n\trequi", "meta": {"filepath": "binding/form_mapping_test.go", "language": "go", "file_size": 34152, "cut_index": 2151, "middle_length": 229}}
{"prefix": "erved.\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\"net/http\"\n\t\"net/textproto\"\n\t\"reflect\"\n)\n\ntype headerBinding struct{}\n\nfunc (headerBinding) Name() string {\n\treturn \"header\"\n}\n\nfunc (headerBinding) Bind(req *http.Request, obj any) error {\n\tif err := mapHeader(obj, req.Header); err != nil {\n\t\treturn err\n\t}\n\n\treturn validate(obj)\n}\n\nfunc mapHeader(ptr any, h map[string][]string) error {\n\treturn mappingByPtr(ptr, headerSo", "suffix": "]string\n\nvar _ setter = headerSource(nil)\n\nfunc (hs headerSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (bool, error) {\n\treturn setByForm(value, field, hs, textproto.CanonicalMIMEHeaderKey(tagValue), opt)\n}", "middle": "urce(h), \"header\")\n}\n\ntype headerSource map[string][", "meta": {"filepath": "binding/header.go", "language": "go", "file_size": 868, "cut_index": 559, "middle_length": 52}}
{"prefix": "tptest\"\n\t\"testing\"\n\t\"time\"\n\t\"unsafe\"\n\n\t\"github.com/gin-gonic/gin/codec/json\"\n\t\"github.com/gin-gonic/gin/render\"\n\tjsoniter \"github.com/json-iterator/go\"\n\t\"github.com/modern-go/reflect2\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\nfunc TestJSONBindingBindBody(t *testing.T) {\n\tvar s struct {\n\t\tFoo string `json:\"foo\"`\n\t}\n\terr := jsonBinding{}.BindBody([]byte(`{\"foo\": \"FOO\"}`), &s)\n\trequire.NoError(t, err)\n\tassert.Equal(t, \"FOO\", s.Foo)\n}\n\nfunc TestJSONBindingBindBodyMap(t *te", "suffix": "llo\"])\n}\n\nfunc TestCustomJsonCodec(t *testing.T) {\n\t// Restore json encoding configuration after testing\n\toldMarshal := json.API\n\tdefer func() {\n\t\tjson.API = oldMarshal\n\t}()\n\t// Custom json api\n\tjson.API = customJsonApi{}\n\n\t// test decode json\n\tobj := cust", "middle": "sting.T) {\n\ts := make(map[string]string)\n\terr := jsonBinding{}.BindBody([]byte(`{\"foo\": \"FOO\",\"hello\":\"world\"}`), &s)\n\trequire.NoError(t, err)\n\tassert.Len(t, s, 2)\n\tassert.Equal(t, \"FOO\", s[\"foo\"])\n\tassert.Equal(t, \"world\", s[\"he", "meta": {"filepath": "binding/json_test.go", "language": "go", "file_size": 5524, "cut_index": 716, "middle_length": 229}}
{"prefix": "/ Copyright 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\n//go:build !nomsgpack\n\npackage binding\n\nimport (\n\t\"bytes\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n\t\"github.com/ugorji/go/codec\"\n)\n\nfunc TestMsgpackBindingBindBody(t *testing.T) {\n\ttype teststruct struct {\n\t\tFoo string `msgpack:\"foo\"`\n\t}\n\tvar s teststruct\n\terr := msgpackBinding{}.BindBody(msgpackBody(t, t", "suffix": "\"}), &s)\n\trequire.NoError(t, err)\n\tassert.Equal(t, \"FOO\", s.Foo)\n}\n\nfunc msgpackBody(t *testing.T, obj any) []byte {\n\tvar bs bytes.Buffer\n\th := &codec.MsgpackHandle{}\n\terr := codec.NewEncoder(&bs, h).Encode(obj)\n\trequire.NoError(t, err)\n\treturn bs.Bytes()\n", "middle": "eststruct{\"FOO", "meta": {"filepath": "binding/msgpack_test.go", "language": "go", "file_size": 785, "cut_index": 513, "middle_length": 14}}
{"prefix": "style\n// license that can be found in the LICENSE file.\n\npackage binding\n\nimport (\n\t\"bytes\"\n\t\"io\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\nfunc TestFormMultipartBindingBindOneFile(t *testing.T) {\n\tvar s struct {\n\t\tFileValue multipart.FileHeader `form:\"file\"`\n\t\tFilePtr *multipart.FileHeader `form:\"file\"`\n\t\tSliceValues []multipart.FileHeader `form:\"file\"`\n\t\tSlicePtrs []*multipart.FileHeader `form:\"file\"`\n\t\tArray", "suffix": "q, &s)\n\trequire.NoError(t, err)\n\n\tassertMultipartFileHeader(t, &s.FileValue, file)\n\tassertMultipartFileHeader(t, s.FilePtr, file)\n\tassert.Len(t, s.SliceValues, 1)\n\tassertMultipartFileHeader(t, &s.SliceValues[0], file)\n\tassert.Len(t, s.SlicePtrs, 1)\n\tassert", "middle": "Values [1]multipart.FileHeader `form:\"file\"`\n\t\tArrayPtrs [1]*multipart.FileHeader `form:\"file\"`\n\t}\n\tfile := testFile{\"file\", \"file1\", []byte(\"hello\")}\n\n\treq := createRequestMultipartFiles(t, file)\n\terr := FormMultipart.Bind(re", "meta": {"filepath": "binding/multipart_form_mapping_test.go", "language": "go", "file_size": 3794, "cut_index": 614, "middle_length": 229}}
{"prefix": "testing\"\n\t\"time\"\n\n\t\"github.com/go-playground/validator/v10\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"github.com/stretchr/testify/require\"\n)\n\ntype testInterface interface {\n\tString() string\n}\n\ntype substructNoValidation struct {\n\tIString string\n\tIInt int\n}\n\ntype mapNoValidationSub map[string]substructNoValidation\n\ntype structNoValidationValues struct {\n\tsubstructNoValidation\n\n\tBoolean bool\n\n\tUinteger uint\n\tInteger int\n\tInteger8 int8\n\tInteger16 int16\n\tInteger32 int32\n\tInteger64 int64\n\tUinteger8 u", "suffix": "\tIntSlice []int\n\tIntPointerSlice []*int\n\tStructPointerSlice []*substructNoValidation\n\tStructSlice []substructNoValidation\n\tInterfaceSlice []testInterface\n\n\tUniversalInterface any\n\tCustomInterface testInterface\n\n\tFloatMap map[str", "middle": "int8\n\tUinteger16 uint16\n\tUinteger32 uint32\n\tUinteger64 uint64\n\n\tFloat32 float32\n\tFloat64 float64\n\n\tString string\n\n\tDate time.Time\n\n\tStruct substructNoValidation\n\tInlinedStruct struct {\n\t\tString []string\n\t\tInteger int\n\t}\n\n", "meta": {"filepath": "binding/validate_test.go", "language": "go", "file_size": 6125, "cut_index": 716, "middle_length": 229}}
{"prefix": "rtinez-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 binding\n\nimport (\n\t\"bytes\"\n\t\"errors\"\n\t\"io\"\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin/codec/json\"\n)\n\n// EnableDecoderUseNumber is used to call the UseNumber method on the JSON\n// Decoder instance. UseNumber causes the Decoder to unmarshal a number into an\n// any as a Number instead of as a float64.\nvar EnableDecoderUseNumber = false\n\n// EnableDecoderDisallowUnkno", "suffix": "h do not match any non-ignored, exported fields in the destination.\nvar EnableDecoderDisallowUnknownFields = false\n\ntype jsonBinding struct{}\n\nfunc (jsonBinding) Name() string {\n\treturn \"json\"\n}\n\nfunc (jsonBinding) Bind(req *http.Request, obj any) error {\n", "middle": "wnFields is used to call the DisallowUnknownFields method\n// on the JSON Decoder instance. DisallowUnknownFields causes the Decoder to\n// return an error when the destination is a struct and the input contains object\n// keys whic", "meta": {"filepath": "binding/json.go", "language": "go", "file_size": 1543, "cut_index": 537, "middle_length": 229}}
{"prefix": "d.\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\"errors\"\n\t\"mime/multipart\"\n\t\"net/http\"\n\t\"reflect\"\n)\n\ntype multipartRequest http.Request\n\nvar _ setter = (*multipartRequest)(nil)\n\nvar (\n\t// ErrMultiFileHeader multipart.FileHeader invalid\n\tErrMultiFileHeader = errors.New(\"unsupported field type for multipart.FileHeader\")\n\n\t// ErrMultiFileHeaderLenInvalid array for []*multipart.FileHeader len invalid\n\tErrMultiFileHeaderLenInv", "suffix": "t.StructField, key string, opt setOptions) (bool, error) {\n\tif files := r.MultipartForm.File[key]; len(files) != 0 {\n\t\treturn setByMultipartFormFile(value, field, files)\n\t}\n\n\treturn setByForm(value, field, r.MultipartForm.Value, key, opt)\n}\n\nfunc setByMult", "middle": "alid = errors.New(\"unsupported len of array for []*multipart.FileHeader\")\n)\n\n// TrySet tries to set a value by the multipart request with the binding a form file\nfunc (r *multipartRequest) TrySet(value reflect.Value, field reflec", "meta": {"filepath": "binding/multipart_form_mapping.go", "language": "go", "file_size": 2244, "cut_index": 563, "middle_length": 229}}
{"prefix": "verned by a MIT style\n// license that can be found in the LICENSE file.\n\npackage binding\n\nimport (\n\t\"errors\"\n\t\"io\"\n\t\"net/http\"\n\n\t\"google.golang.org/protobuf/proto\"\n)\n\ntype protobufBinding struct{}\n\nfunc (protobufBinding) Name() string {\n\treturn \"protobuf\"\n}\n\nfunc (b protobufBinding) Bind(req *http.Request, obj any) error {\n\tbuf, err := io.ReadAll(req.Body)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn b.BindBody(buf, obj)\n}\n\nfunc (protobufBinding) BindBody(body []byte, obj any) error {\n\tmsg, ok := obj.(proto.Mes", "suffix": "oMessage\")\n\t}\n\tif err := proto.Unmarshal(body, msg); err != nil {\n\t\treturn err\n\t}\n\t// Here it's same to return validate(obj), but until now we can't add\n\t// `binding:\"\"` to the struct which automatically generate by gen-proto\n\treturn nil\n\t// return validat", "middle": "sage)\n\tif !ok {\n\t\treturn errors.New(\"obj is not Prot", "meta": {"filepath": "binding/protobuf.go", "language": "go", "file_size": 923, "cut_index": 606, "middle_length": 52}}
{"prefix": "e 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 json\n\nimport \"io\"\n\n// API the json codec in use.\nvar API Core\n\n// Core the api for json codec.\ntype Core interface {\n\tMarshal(v any) ([]byte, error)\n\tUnmarshal(data []byte, v any) error\n\tMarshalIndent(v any, prefix, indent string) ([]byte, error)\n\tNewEncoder(writer io.Writer) Encoder\n\tNewDecoder(reader io.Reader) Decoder\n}\n\n// Encoder an interface writes JSON values t", "suffix": "nd \\u003e\n\t// to avoid certain safety problems that can arise when embedding JSON in HTML.\n\t//\n\t// In non-HTML settings where the escaping interferes with the readability\n\t// of the output, SetEscapeHTML(false) disables this behavior.\n\tSetEscapeHTML(on boo", "middle": "o an output stream.\ntype Encoder interface {\n\t// SetEscapeHTML specifies whether problematic HTML characters\n\t// should be escaped inside JSON quoted strings.\n\t// The default behavior is to escape &, <, and > to \\u0026, \\u003c, a", "meta": {"filepath": "codec/json/api.go", "language": "go", "file_size": 1942, "cut_index": 537, "middle_length": 229}}
{"prefix": "y a MIT style\n// license that can be found in the LICENSE file.\n\n//go:build !jsoniter && !go_json && !(sonic && (linux || windows || darwin))\n\npackage json\n\nimport (\n\t\"encoding/json\"\n\t\"io\"\n)\n\n// Package indicates what library is being used for JSON encoding.\nconst Package = \"encoding/json\"\n\nfunc init() {\n\tAPI = jsonApi{}\n}\n\ntype jsonApi struct{}\n\nfunc (j jsonApi) Marshal(v any) ([]byte, error) {\n\treturn json.Marshal(v)\n}\n\nfunc (j jsonApi) Unmarshal(data []byte, v any) error {\n\treturn json.Unmarshal(data, v)", "suffix": "dent string) ([]byte, error) {\n\treturn json.MarshalIndent(v, prefix, indent)\n}\n\nfunc (j jsonApi) NewEncoder(writer io.Writer) Encoder {\n\treturn json.NewEncoder(writer)\n}\n\nfunc (j jsonApi) NewDecoder(reader io.Reader) Decoder {\n\treturn json.NewDecoder(reade", "middle": "\n}\n\nfunc (j jsonApi) MarshalIndent(v any, prefix, in", "meta": {"filepath": "codec/json/json.go", "language": "go", "file_size": 919, "cut_index": 606, "middle_length": 52}}
{"prefix": "tp\"\n\t\"reflect\"\n\n\t\"github.com/gin-gonic/gin/internal/bytesconv\"\n)\n\ntype plainBinding struct{}\n\nfunc (plainBinding) Name() string {\n\treturn \"plain\"\n}\n\nfunc (plainBinding) Bind(req *http.Request, obj any) error {\n\tall, err := io.ReadAll(req.Body)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn decodePlain(all, obj)\n}\n\nfunc (plainBinding) BindBody(body []byte, obj any) error {\n\treturn decodePlain(body, obj)\n}\n\nfunc decodePlain(data []byte, obj any) error {\n\tif obj == nil {\n\t\treturn nil\n\t}\n\n\tv := reflect.ValueOf(obj)\n", "suffix": "return nil\n\t\t}\n\t\tv = v.Elem()\n\t}\n\n\tif v.Kind() == reflect.String {\n\t\tv.SetString(bytesconv.BytesToString(data))\n\t\treturn nil\n\t}\n\n\tif _, ok := v.Interface().([]byte); ok {\n\t\tv.SetBytes(data)\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"type (%T) unknown type\", v)\n}", "middle": "\n\tfor v.Kind() == reflect.Ptr {\n\t\tif v.IsNil() {\n\t\t\t", "meta": {"filepath": "binding/plain.go", "language": "go", "file_size": 868, "cut_index": 559, "middle_length": 52}}
{"prefix": "ource code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\n//go:build jsoniter\n\npackage json\n\nimport (\n\t\"io\"\n\n\tjsoniter \"github.com/json-iterator/go\"\n)\n\n// Package indicates what library is being used for JSON encoding.\nconst Package = \"github.com/json-iterator/go\"\n\nfunc init() {\n\tAPI = jsoniterApi{}\n}\n\nvar json = jsoniter.ConfigCompatibleWithStandardLibrary\n\ntype jsoniterApi struct{}\n\nfunc (j jsoniterApi) Marshal(v any) ([]byte, error) {\n\treturn json.Marshal(v)\n}\n\nfunc (j json", "suffix": "rn json.Unmarshal(data, v)\n}\n\nfunc (j jsoniterApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {\n\treturn json.MarshalIndent(v, prefix, indent)\n}\n\nfunc (j jsoniterApi) NewEncoder(writer io.Writer) Encoder {\n\treturn json.NewEncoder(writer)\n}\n", "middle": "iterApi) Unmarshal(data []byte, v any) error {\n\tretu", "meta": {"filepath": "codec/json/jsoniter.go", "language": "go", "file_size": 985, "cut_index": 582, "middle_length": 52}}
{"prefix": "t/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 TestFileSystem_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 := &FileSystem{mockFS}\n\n\tfile, err := fs.Open(\"foo\")\n\n\trequire.NoErr", "suffix": "TestFileSystem_Open_err(t *testing.T) {\n\ttestError := errors.New(\"mock\")\n\tmockFS := &mockFileSystem{\n\t\topen: func(_ string) (http.File, error) {\n\t\t\treturn nil, testError\n\t\t},\n\t}\n\tfs := &FileSystem{mockFS}\n\n\tfile, err := fs.Open(\"foo\")\n\n\trequire.ErrorIs(t, ", "middle": "or(t, err)\n\tassert.Equal(t, testFile, file)\n}\n\nfunc ", "meta": {"filepath": "internal/fs/fs_test.go", "language": "go", "file_size": 894, "cut_index": 547, "middle_length": 52}}
{"prefix": "d.\n// Use of this source code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\npackage bytesconv\n\nimport (\n\t\"bytes\"\n\tcRand \"crypto/rand\"\n\t\"math/rand\"\n\t\"strings\"\n\t\"testing\"\n\t\"time\"\n)\n\nvar (\n\ttestString = \"Albert Einstein: Logic will get you from A to B. Imagination will take you everywhere.\"\n\ttestBytes = []byte(testString)\n)\n\nfunc rawBytesToStr(b []byte) string {\n\treturn string(b)\n}\n\nfunc rawStrToBytes(s string) []byte {\n\treturn []byte(s)\n}\n\n// go test -v\n\nfunc TestBytesToString", "suffix": "ToStringEmpty(t *testing.T) {\n\tif got := BytesToString([]byte{}); got != \"\" {\n\t\tt.Fatalf(\"BytesToString([]byte{}) = %q; want empty string\", got)\n\t}\n\tif got := BytesToString(nil); got != \"\" {\n\t\tt.Fatalf(\"BytesToString(nil) = %q; want empty string\", got)\n\t}\n", "middle": "(t *testing.T) {\n\tdata := make([]byte, 1024)\n\tfor range 100 {\n\t\t_, err := cRand.Read(data)\n\t\tif err != nil {\n\t\t\tt.Fatal(err)\n\t\t}\n\t\tif rawBytesToStr(data) != BytesToString(data) {\n\t\t\tt.Fatal(\"don't match\")\n\t\t}\n\t}\n}\n\nfunc TestBytes", "meta": {"filepath": "internal/bytesconv/bytesconv_test.go", "language": "go", "file_size": 2810, "cut_index": 563, "middle_length": 229}}
{"prefix": "l 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 go_json\n\npackage json\n\nimport (\n\t\"io\"\n\n\t\"github.com/goccy/go-json\"\n)\n\n// Package indicates what library is being used for JSON encoding.\nconst Package = \"github.com/goccy/go-json\"\n\nfunc init() {\n\tAPI = gojsonApi{}\n}\n\ntype gojsonApi struct{}\n\nfunc (j gojsonApi) Marshal(v any) ([]byte, error) {\n\treturn json.Marshal(v)\n}\n\nfunc (j gojsonApi) Unmarshal(data []byte, v any) error {", "suffix": "i) MarshalIndent(v any, prefix, indent string) ([]byte, error) {\n\treturn json.MarshalIndent(v, prefix, indent)\n}\n\nfunc (j gojsonApi) NewEncoder(writer io.Writer) Encoder {\n\treturn json.NewEncoder(writer)\n}\n\nfunc (j gojsonApi) NewDecoder(reader io.Reader) D", "middle": "\n\treturn json.Unmarshal(data, v)\n}\n\nfunc (j gojsonAp", "meta": {"filepath": "codec/json/go_json.go", "language": "go", "file_size": 898, "cut_index": 547, "middle_length": 52}}
{"prefix": "ource code is governed by a MIT style\n// license that can be found in the LICENSE file.\n\n//go:build sonic && (linux || windows || darwin)\n\npackage json\n\nimport (\n\t\"io\"\n\n\t\"github.com/bytedance/sonic\"\n)\n\n// Package indicates what library is being used for JSON encoding.\nconst Package = \"github.com/bytedance/sonic\"\n\nfunc init() {\n\tAPI = sonicApi{}\n}\n\nvar json = sonic.ConfigStd\n\ntype sonicApi struct{}\n\nfunc (j sonicApi) Marshal(v any) ([]byte, error) {\n\treturn json.Marshal(v)\n}\n\nfunc (j sonicApi) Unmarshal(data", "suffix": " v)\n}\n\nfunc (j sonicApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {\n\treturn json.MarshalIndent(v, prefix, indent)\n}\n\nfunc (j sonicApi) NewEncoder(writer io.Writer) Encoder {\n\treturn json.NewEncoder(writer)\n}\n\nfunc (j sonicApi) NewDecoder", "middle": " []byte, v any) error {\n\treturn json.Unmarshal(data,", "meta": {"filepath": "codec/json/sonic.go", "language": "go", "file_size": 953, "cut_index": 582, "middle_length": 52}}