fix: Correct typos, improve documentation clarity, and remove dead code (#4511)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix: correct typos and improve documentation clarity - Fix typo "Oupps" to "Oops" in recovery test panic messages - Fix confusing documentation in Bind() and ShouldBind() methods that incorrectly stated "JSON or XML as a JSON input" - Remove double period in StaticFileFS documentation comment - Remove unused ErrorTypeNu constant that had duplicate comment with ErrorTypeAny and was never used in the codebase * tech: Fix the pull request routing link
authored by Mahan Adhikari · committed by GitHub · parent d7776de · Browse files · 5 files·+19 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+19 added−21 removed
- other:+19 added−21 removed
Provenance
- Commit
8e07d37- Tree
87948d5- Author
Mahan Adhikari <41227164+mahanadh@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
d7776de
5 files changed+19 added−21 removed
modified:context.go+4 added-4 removed
749 unmodified lines750 //751 // "application/json" --> JSON binding752 // "application/xml" --> XML binding753 //754-// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.755-// It decodes the json payload into the struct specified as a pointer.754+// It parses the request's body based on the Content-Type (e.g., JSON or XML).755+// It decodes the payload into the struct specified as a pointer.756 // It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.757 func (c *Context) Bind(obj any) error {758 b := binding.Default(c.Request.Method, c.ContentType())759 return c.MustBindWith(obj, b)71 unmodified lines831 //832 // "application/json" --> JSON binding833 // "application/xml" --> XML binding834 //835-// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.836-// It decodes the json payload into the struct specified as a pointer.835+// It parses the request's body based on the Content-Type (e.g., JSON or XML).836+// It decodes the payload into the struct specified as a pointer.837 // Like c.Bind() but this method does not set the response status code to 400 or abort if input is not valid.838 func (c *Context) ShouldBind(obj any) error {839 b := binding.Default(c.Request.Method, c.ContentType())840 return c.ShouldBindWith(obj, b)642 unmodified linesmodified:CONTRIBUTING.md+1 added-1 removed
34 unmodified lines353637383939404134 unmodified lines- Your pull request should have no more than two commits — squash them if necessary.- All tests pass in available continuous integration systems (e.g., GitHub Actions).- Add or modify tests to cover your code changes.- If your pull request introduces a new feature, document it in [`docs/doc.md`](docs/doc.md), not in the README.- Follow the checklist in the [Pull Request Template](.github/PULL_REQUEST_TEMPLATE.md:1).- Follow the checklist in the [Pull Request Template](.github/PULL_REQUEST_TEMPLATE.md).
Thank you for contributing!modified:errors.go-2 removed
24 unmodified lines25 // ErrorTypePublic indicates a public error.26 ErrorTypePublic ErrorType = 1 << 127 // ErrorTypeAny indicates any other error.28 ErrorTypeAny ErrorType = 1<<64 - 129- // ErrorTypeNu indicates any other error.30- ErrorTypeNu = 229 )30 31 // Error represents a error's specification.32 type Error struct {141 unmodified linesmodified:recovery_test.go+13 added-13 removed
20 unmodified lines21 password := "my-super-secret-password"22 router.Use(RecoveryWithWriter(buffer))23 router.GET("/recovery", func(c *Context) {24 c.AbortWithStatus(http.StatusBadRequest)25- panic("Oupps, Houston, we have a problem")25+ panic("Oops, Houston, we have a problem")26 })27 // RUN28 w := PerformRequest(router, http.MethodGet, "/recovery",29 header{21 unmodified lines51 buffer := new(strings.Builder)52 router := New()53 router.Use(RecoveryWithWriter(buffer))54 router.GET("/recovery", func(_ *Context) {55- panic("Oupps, Houston, we have a problem")55+ panic("Oops, Houston, we have a problem")56 })57 // RUN58 w := PerformRequest(router, http.MethodGet, "/recovery")59 // TEST60 assert.Equal(t, http.StatusInternalServerError, w.Code)61 assert.Contains(t, buffer.String(), "panic recovered")62- assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")62+ assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem")63 assert.Contains(t, buffer.String(), t.Name())64 assert.NotContains(t, buffer.String(), "GET /recovery")65 66 // Debug mode prints the request12 unmodified lines79 router := New()80 router.Use(RecoveryWithWriter(nil))81 router.GET("/recovery", func(c *Context) {82 c.AbortWithStatus(http.StatusBadRequest)83- panic("Oupps, Houston, we have a problem")83+ panic("Oops, Houston, we have a problem")84 })85 // RUN86 w := PerformRequest(router, http.MethodGet, "/recovery")87 // TEST73 unmodified lines161 c.AbortWithStatus(http.StatusBadRequest)162 }163 router.Use(CustomRecoveryWithWriter(buffer, handleRecovery))164 router.GET("/recovery", func(_ *Context) {165- panic("Oupps, Houston, we have a problem")165+ panic("Oops, Houston, we have a problem")166 })167 // RUN168 w := PerformRequest(router, http.MethodGet, "/recovery")169 // TEST170 assert.Equal(t, http.StatusBadRequest, w.Code)171 assert.Contains(t, buffer.String(), "panic recovered")172- assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")172+ assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem")173 assert.Contains(t, buffer.String(), t.Name())174 assert.NotContains(t, buffer.String(), "GET /recovery")175 176 // Debug mode prints the request3 unmodified lines180 // TEST181 assert.Equal(t, http.StatusBadRequest, w.Code)182 assert.Contains(t, buffer.String(), "GET /recovery")183 184- assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String())184+ assert.Equal(t, strings.Repeat("Oops, Houston, we have a problem", 2), errBuffer.String())185 186 SetMode(TestMode)187 }188 7 unmodified lines196 c.AbortWithStatus(http.StatusBadRequest)197 }198 router.Use(CustomRecovery(handleRecovery))199 router.GET("/recovery", func(_ *Context) {200- panic("Oupps, Houston, we have a problem")200+ panic("Oops, Houston, we have a problem")201 })202 // RUN203 w := PerformRequest(router, http.MethodGet, "/recovery")204 // TEST205 assert.Equal(t, http.StatusBadRequest, w.Code)206 assert.Contains(t, buffer.String(), "panic recovered")207- assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")207+ assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem")208 assert.Contains(t, buffer.String(), t.Name())209 assert.NotContains(t, buffer.String(), "GET /recovery")210 211 // Debug mode prints the request3 unmodified lines215 // TEST216 assert.Equal(t, http.StatusBadRequest, w.Code)217 assert.Contains(t, buffer.String(), "GET /recovery")218 219- assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String())219+ assert.Equal(t, strings.Repeat("Oops, Houston, we have a problem", 2), errBuffer.String())220 221 SetMode(TestMode)222 }223 7 unmodified lines231 c.AbortWithStatus(http.StatusBadRequest)232 }233 router.Use(RecoveryWithWriter(DefaultErrorWriter, handleRecovery))234 router.GET("/recovery", func(_ *Context) {235- panic("Oupps, Houston, we have a problem")235+ panic("Oops, Houston, we have a problem")236 })237 // RUN238 w := PerformRequest(router, http.MethodGet, "/recovery")239 // TEST240 assert.Equal(t, http.StatusBadRequest, w.Code)241 assert.Contains(t, buffer.String(), "panic recovered")242- assert.Contains(t, buffer.String(), "Oupps, Houston, we have a problem")242+ assert.Contains(t, buffer.String(), "Oops, Houston, we have a problem")243 assert.Contains(t, buffer.String(), t.Name())244 assert.NotContains(t, buffer.String(), "GET /recovery")245 246 // Debug mode prints the request3 unmodified lines250 // TEST251 assert.Equal(t, http.StatusBadRequest, w.Code)252 assert.Contains(t, buffer.String(), "GET /recovery")253 254- assert.Equal(t, strings.Repeat("Oupps, Houston, we have a problem", 2), errBuffer.String())254+ assert.Equal(t, strings.Repeat("Oops, Houston, we have a problem", 2), errBuffer.String())255 256 SetMode(TestMode)257 }258 111 unmodified linesmodified:routergroup.go+1 added-1 removed
167 unmodified lines168 c.File(filepath)169 })170 }171 172-// StaticFileFS works just like `StaticFile` but a custom `http.FileSystem` can be used instead..172+// StaticFileFS works just like `StaticFile` but a custom `http.FileSystem` can be used instead.173 // router.StaticFileFS("favicon.ico", "./resources/favicon.ico", Dir{".", false})174 // Gin by default uses: gin.Dir()175 func (group *RouterGroup) StaticFileFS(relativePath, filepath string, fs http.FileSystem) IRoutes {176 return group.staticFileHandler(relativePath, func(c *Context) {83 unmodified lines