httpjson

package
v0.1.66 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package httpjson provides generic JSON HTTP response helpers.

It keeps handler code clean by encapsulating the marshal → set Content-Type → write status pattern that every JSON API endpoint repeats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentType

func ContentType(next http.Handler) http.Handler

ContentType is middleware that sets the Content-Type header to application/json.

func Error

func Error(w http.ResponseWriter, status int, message string)

Error writes a JSON error response with the given HTTP status code.

func Write

func Write(w http.ResponseWriter, status int, data any)

Write marshals data as JSON and writes it with the given HTTP status code. If marshalling fails, it falls back to a 500 error response.

Types

This section is empty.

Jump to

Keyboard shortcuts

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