Back to all reviewers

Use standard HTTP constants

gin-gonic/gin
Based on 2 comments
Go

Always use the standard HTTP status constants from the `http` package instead of raw numeric values in your networking code. This practice improves code readability, maintainability, and helps prevent errors when working with HTTP responses.

Networking Go

Reviewer Prompt

Always use the standard HTTP status constants from the http package instead of raw numeric values in your networking code. This practice improves code readability, maintainability, and helps prevent errors when working with HTTP responses.

For example, instead of:

writer.WriteHeader(500)
c.AsciiJSON(204, []string{"lang", "Go语言"})

Use the semantic constants:

writer.WriteHeader(http.StatusInternalServerError)
c.AsciiJSON(http.StatusNoContent, []string{"lang", "Go语言"})

This approach makes your code more descriptive and self-documenting. It also ensures consistency across the codebase and makes it easier for other developers to understand the HTTP status codes being used without having to memorize numeric values.

2
Comments Analyzed
Go
Primary Language
Networking
Category

Source Discussions