Skip to main content

http_utils.go

http_utils.go - Overview

  1. Overview

This file defines a utility function withCacheControl to add a Cache-Control header to HTTP responses and sets a default cache age for autocomplete endpoints.

  1. Detailed Documentation

Variables

  • AutoCompleteCacheControlAge
    • Purpose: Specifies the maximum age for the Cache-Control header for autocomplete endpoints.
    • Type: time.Duration
    • Value: 60 seconds.

Functions

  • withCacheControl
    • Purpose: Wraps an http.HandlerFunc to add a Cache-Control header to the HTTP response.
    • Parameters:
      • maxAge (time.Duration): The maximum age in seconds for which the response should be cached.
      • h (http.HandlerFunc): The HTTP handler function to wrap.
    • Returns: http.HandlerFunc: A new HTTP handler function that sets the Cache-Control header before calling the original handler.
  1. Code Examples

None

  1. Clarity and Accuracy

The documentation is derived directly from the code and comments provided.

  1. Markdown & MDX Perfection

All markdown syntax is valid, and no MDX errors should occur.

  1. Edge Cases To Avoid Breaking MDX:

No edge cases were detected.

  1. Getting Started Relevance

Include in Getting Started: NO