restapi

package
v0.115.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const KeyHeader = "x-api-key" // Header for API key

Variables

View Source
var (
	ErrInvalidApiKey     = errors.New("invalid api key")
	ErrInvalidAction     = errors.New("invalid action")
	ErrInvalidHTTPMethod = errors.New("invalid http method")
)

Functions

func JSONError added in v0.115.0

func JSONError(w http.ResponseWriter, err, details any, jobId string, code int)

JSONError writes an error response to the client in JSON format.

func JSONResponse added in v0.115.0

func JSONResponse(w http.ResponseWriter, content any, jobId string, code int)

JSONResponse writes a successful response in the common JSON envelope.

func ResolveRequestIP added in v0.115.0

func ResolveRequestIP(remoteAddr, trustedProxyHeader string, headers http.Header, trustedProxyNetworks []netip.Prefix) string

ResolveRequestIP determines the client IP address from the request, considering trusted proxy headers and networks.

func ValidateApiKey

func ValidateApiKey(r *http.Request, apiKey string) bool

ValidateApiKey checks if the provided API key matches the one in the request header.

Types

type ErrorResponse added in v0.115.0

type ErrorResponse struct {
	Error string `json:"error"`
	Response
}

ErrorResponse inherits from Response and adds an error message.

type Response added in v0.115.0

type Response struct {
	Content any    `json:"content,omitempty"`
	JobID   string `json:"job_id,omitempty"`
}

Response is the common JSON envelope for successful REST responses.

Jump to

Keyboard shortcuts

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