Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSecurityHeaders ¶
AddSecurityHeaders is a middleware function that adds security headers to the HTTP response. It takes a http.Handler as an argument which represents the next handler to be executed in the middleware chain. The function adds several security headers to the response, including: - Strict-Transport-Security: This header is used to enforce secure (HTTP over SSL/TLS) connections to the server. - X-Content-Type-Options: This header is used to protect against MIME type confusion attacks. - X-Frame-Options: This header is used to indicate whether a browser should be allowed to render a page in a <frame>, <iframe>, <embed> or <object>. - Content-Security-Policy: This header is used to prevent a wide range of attacks, including Cross-site scripting and other cross-site injections. - X-XSS-Protection: This header is used to configure the XSS Auditor in Chrome, Internet Explorer and Safari (though it's being deprecated). - Cache-Control: This header is used to specify directives for caching mechanisms in both requests and responses.
Parameters: next: The next http.Handler to be executed in the middleware chain.
Returns: A http.Handler that can be used in the middleware chain.
func ContentTypeJSON ¶
ContentTypeJSON is a middleware function that checks if the request's content type is application/json. It takes a http.Handler as an argument which represents the next handler to be executed in the middleware chain. If the content type of the request is not application/json, it responds with a JSON message and a status of http.StatusUnsupportedMediaType. If the content type is application/json, it calls the next handler in the middleware chain.
Parameters: next: The next http.Handler to be executed in the middleware chain.
Returns: A http.Handler that can be used in the middleware chain.
func ContentTypeUTF8 ¶
ContentTypeUTF8 is a middleware function that checks if the request's content type is charset=utf-8. It takes a http.Handler as an argument which represents the next handler to be executed in the middleware chain. If the content type of the request is not charset=utf-8, it responds with a JSON message and a status of http.StatusUnsupportedMediaType. If the content type is charset=utf-8, it calls the next handler in the middleware chain.
Parameters: next: The next http.Handler to be executed in the middleware chain.
Returns: A http.Handler that can be used in the middleware chain.
func LogRequestWithZerolog ¶
LogRequestWithZerolog is a middleware function that logs HTTP requests and responses. It logs the start and end time of the request, the duration, the request details (address, path, method, headers, queries), and the response details (status, bytes written, headers). If the response status is 400 or above, it logs a warning. Otherwise, it logs an info message.
The function takes the next http.Handler to call in the middleware chain. It returns a new http.Handler that wraps the original handler with logging functionality.
func Service ¶
Service is a middleware function that injects service name and version into the request context. It takes the next http.Handler, service name, and service version as parameters. The middleware adds the service name and version to the request context and then calls the next handler.
Parameters: - next: The next http.Handler in the middleware chain. - name: The name of the service. - version: The version of the service.
Returns: - http.Handler: A new http.Handler that wraps the original handler with the added context.
Types ¶
This section is empty.