Documentation
¶
Overview ¶
Package handlers defines HTTP handlers and middleware for the URL shortener service. It provides functionality to shorten URLs and redirect to original URLs based on the generated short identifiers. The package uses Google Cloud Datastore for storage of the URL mappings and leverages middleware to restrict access to certain operations.
Copyright (c) 2023 H0llyW00dzZ
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Logger *zap.Logger
Logger is a package-level variable to access the zap logger throughout the handlers package. It is intended to be used by other functions within the package for logging purposes.
Functions ¶
func InternalOnly ¶
func InternalOnly() gin.HandlerFunc
InternalOnly creates a middleware that restricts access to a route to internal services only. It checks for a specific header containing a secret value that should match an environment variable to allow the request to proceed. If the secret does not match or is not provided, the request is aborted with a 403 Forbidden status.
func RegisterHandlersGin ¶
RegisterHandlersGin registers the HTTP handlers for the URL shortener service using the Gin web framework. It sets up the routes for retrieving, creating, and updating shortened URLs. The InternalOnly middleware is applied to the POST and PUT routes to protect them from public access.
Types ¶
type CreateURLPayload ¶ added in v0.1.9
type CreateURLPayload struct {
URL string `json:"url"`
}
CreateURLPayload defines the structure for the JSON payload when creating a new URL. It contains a single field, URL, which is the original URL to be shortened.
type DeleteURLPayload ¶ added in v0.1.10
DeleteURLPayload defines the structure for the JSON payload when deleting a URL.
type UpdateURLPayload ¶ added in v0.1.9
UpdateURLPayload defines the structure for the JSON payload when updating an existing URL.