* test: add comprehensive unit tests for Context.File() method
- Add TestContextFile with multiple test scenarios in context_test.go
- Add simplified tests in context_file_test.go
- Cover file serving, 404 handling, directory access, HEAD requests, and Range requests
- All tests pass successfully
* fix: resolve gci formatting issues in test files
* fix: correct test file paths and add test file to gin directory
* move test_file.txt to testdata directory as suggested by maintainer
* fix: update test file paths to use testdata directory
- Fix 'an url' to 'a URL' in logger.go comment
- Fix 'an form' to 'a form' in binding/form_mapping.go comment
- Improve grammar consistency in code documentation
* refactor(context): refactor keys to `map[any]any`
Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
* refactor(context): refactor keys to `map[any]any`
Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
* style(context): remove empty lines before GetInt16, GetIntSlice, and GetStringMapString methods
- Remove unnecessary empty lines in the context.go file
- Improve code readability and consistency
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
* refactor(context): simplify GetStringSlice function
- Replace manual type assertion with generic getTyped function
- Reduce code duplication and improve type safety
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
* test(context): improve context.Set and context.Get tests
- Split existing test into separate functions for different scenarios
- Add test for setting and getting values with any key type
- Add test for handling non-comparable keys
- Improve assertions to check for key existence and value correctness
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
* refactor(context): replace fmt.Errorf with fmt.Sprintf in panic message
* test(context): remove trailing hyphen from context_test.go
* refactor(context): improve error message for missing key in context
- Remove unnecessary quotes around the key in the error message
- Simplify the error message format for better readability
* test(context): improve panic test message for non-existent key
---------
Signed-off-by: Flc゛ <four_leaf_clover@foxmail.com>
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
- Update golangci.yml to use 'any' instead of 'interface{}' in gofmt
- Modify debug.go, plain.go, and render_test.go to use 'any' type
- Improve code readability and follow modern Go conventions
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
* Bind: return 413 status code when error is `http.MaxBytesError`
The Go standard library includes a method `http.MaxBytesReader` that allows limiting the request body. For example, users can create a middleware like:
```go
func MiddlewareMaxBodySize(c *gin.Context) {
// Limit request body to 100 bytes
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 100)
c.Next()
}
```
When the body exceeds the limit, reading from the request body returns an error of type `http.MaxBytesError`.
This PR makes sure that when the error is of kind `http.MaxBytesError`, Gin returns the correct status code 413 (Request Entity Too Large) instead of a generic 400 (Bad Request).
* Disable test when using sonic
* Fix
* Disable for go-json too
* Add references to GitHub issues
* Test that the response is 400 for sonic and go-json
* ci: update golangci-lint configuration and lint settings
- Update golangci-lint to version 2
- Enable new linters and adjust existing ones
- Update lint settings across multiple test files
- Remove unused struct and variable checks
- Add new lint exclusions for generated code and specific directories
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
* ci(github): update golangci-lint-action to v8 and lint version to v2.3.4
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
* ci: downgrade golangci-lint to v2.1.6
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
* ci(golangci): add gofumpt linter and fix related issues- Added gofumpt linter to .golangci.yml
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
* test: ignore testifylint and gofumpt lints in specific test cases
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
* build(deps): remove golang.org/x/lint
- Remove golang.org/x/lint package from go.mod
- Update related dependencies in go.sum
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
* build(deps): downgrade golang.org/x/mod and golang.org/x/tools
- Downgrade golang.org/x/mod from v0.24.0 to v0.18.0
- Downgrade golang.org/x/tools from v0.33.0 to v.22.0
These changes are made to address compatibility issues with the current project setup.
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>
---------
Signed-off-by: Flc <four_leaf_clover@foxmail.com>
Signed-off-by: flc1125 <four_leaf_clover@foxmail.com>