handlers

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

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

View Source
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

func RegisterHandlersGin(router *gin.Engine, datastoreClient *datastore.Client)

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.

func SetLogger added in v0.1.7

func SetLogger(logger *zap.Logger)

SetLogger sets the logger instance for the package.

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

type DeleteURLPayload struct {
	ID  string `json:"id"`
	URL string `json:"url"`
}

DeleteURLPayload defines the structure for the JSON payload when deleting a URL.

type UpdateURLPayload added in v0.1.9

type UpdateURLPayload struct {
	OldURL string `json:"old_url"`
	NewURL string `json:"new_url"`
}

UpdateURLPayload defines the structure for the JSON payload when updating an existing URL.

Jump to

Keyboard shortcuts

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