httpserver

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package httpserver provides common HTTP server functionality.

Index

Constants

View Source
const (
	MediaTypeNDJson = "application/x-ndjson"
	MediaTypeJson   = "application/json"
	MediaTypeAny    = "*/*"
)

Variables

This section is empty.

Functions

func AcceptsMediaType added in v0.13.0

func AcceptsMediaType(w http.ResponseWriter, r *http.Request, strict bool, mts ...string) (string, bool)

AcceptsMediaType checks whether the request Accept header matches one of the given media types and returns the first match. When strict is false and Accept is empty, it accepts. On mismatch or invalid Accept, it writes StatusNotAcceptable and returns false.

func EnableCors added in v0.13.0

func EnableCors(w http.ResponseWriter)

EnableCors sets Access-Control-Allow-Origin to allow any origin.

func HandleError

func HandleError(w http.ResponseWriter, err error, reqType string)

func MethodOK added in v0.5.9

func MethodOK(w http.ResponseWriter, r *http.Request, method string) bool

func WriteJsonResponse

func WriteJsonResponse(w http.ResponseWriter, status int, body []byte)

Types

This section is empty.

Jump to

Keyboard shortcuts

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