Documentation
¶
Overview ¶
Deprecated: This package is intended for older projects transitioning from OPA v0.x and will remain for the lifetime of OPA v1.x, but its use is not recommended. For newer features and behaviours, such as defaulting to the Rego v1 syntax, use the corresponding components in the github.com/open-policy-agent/opa/v1 package instead. See https://www.openpolicyagent.org/docs/latest/v0-compatibility/ for more information.
Package writer contains utilities for writing responses in the server.
Index ¶
- func Bytes(w http.ResponseWriter, code int, bs []byte)
- func Error(w http.ResponseWriter, status int, err *types.ErrorV1)
- func ErrorAuto(w http.ResponseWriter, err error)
- func ErrorString(w http.ResponseWriter, status int, code string, err error)
- func HTTPStatus(code int) http.HandlerFunc
- func JSON(w http.ResponseWriter, code int, v interface{}, pretty bool)
- func JSONOK(w http.ResponseWriter, v interface{}, pretty bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bytes ¶
func Bytes(w http.ResponseWriter, code int, bs []byte)
Bytes writes a response with the specified status code and bytes. Deprecated: Unused in OPA, will be removed in the future.
func Error ¶
func Error(w http.ResponseWriter, status int, err *types.ErrorV1)
Error writes a response with specified status and error response.
func ErrorAuto ¶
func ErrorAuto(w http.ResponseWriter, err error)
ErrorAuto writes a response with status and code set automatically based on the type of err.
func ErrorString ¶
func ErrorString(w http.ResponseWriter, status int, code string, err error)
ErrorString writes a response with specified status, code, and message set to the err's string representation.
func HTTPStatus ¶ added in v0.6.0
func HTTPStatus(code int) http.HandlerFunc
HTTPStatus is used to set a specific status code Adapted from https://stackoverflow.com/questions/27711154/what-response-code-to-return-on-a-non-supported-http-method-on-rest
func JSON ¶
func JSON(w http.ResponseWriter, code int, v interface{}, pretty bool)
JSON writes a response with the specified status code and object. The object will be JSON serialized. Deprecated: This method is problematic when using a non-200 status `code`: if encoding the payload fails, it'll print "superfluous call to WriteHeader()" logs.
func JSONOK ¶ added in v0.54.0
func JSONOK(w http.ResponseWriter, v interface{}, pretty bool)
JSONOK is a helper for status "200 OK" responses
Types ¶
This section is empty.