middleware

package
v0.0.0-...-128919f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSecurityHeaders

func AddSecurityHeaders(next http.Handler) http.Handler

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

func ContentTypeJSON(next http.Handler) http.Handler

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

func ContentTypeUTF8(next http.Handler) http.Handler

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

func LogRequestWithZerolog(next http.Handler) http.Handler

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

func Service(next http.Handler, name, version string) http.Handler

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL