httputil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package httputil provides shared HTTP helper utilities used across multiple HTTP-facing packages (server, proxy, etc.).

Index

Constants

View Source
const GitHubUserAgent = "awmg/1.0"

GitHubUserAgent is the User-Agent header value sent on all GitHub API requests.

Variables

This section is empty.

Functions

func ApplyGitHubAPIHeaders added in v0.3.1

func ApplyGitHubAPIHeaders(req *http.Request, authHeader string)

ApplyGitHubAPIHeaders sets the standard GitHub API request headers on req. authHeader should be the full Authorization header value (e.g. "token xyz" or "Bearer xyz"). When authHeader is empty no Authorization header is set, which is appropriate when the caller has already decided that no auth is available.

func IsTransientHTTPError added in v0.2.25

func IsTransientHTTPError(statusCode int) bool

IsTransientHTTPError returns true for status codes that indicate a temporary server-side condition (rate-limiting or transient failure) worth retrying.

func ParseRateLimitResetHeader added in v0.2.20

func ParseRateLimitResetHeader(value string) time.Time

ParseRateLimitResetHeader parses the Unix-timestamp value of the X-RateLimit-Reset HTTP header into a time.Time. Returns zero time when the header value is absent or malformed.

func WriteErrorResponse added in v0.3.2

func WriteErrorResponse(w http.ResponseWriter, statusCode int, code, message string)

WriteErrorResponse writes a JSON error response with a consistent {"error": code, "message": message} shape. Both the server and proxy packages should use this helper so that API consumers always receive the same error shape.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, statusCode int, body interface{})

WriteJSONResponse sets the Content-Type header, writes the status code, and encodes body as JSON. It centralises the three-line pattern used across HTTP handlers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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