utils

package
v0.0.0-...-d3e8332 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCacaoHeaders

func GetCacaoHeaders(r *http.Request) (actor string, emulator string, isAdmin bool)

GetCacaoHeaders returns headers added by Cacao Currently, this includes username, emulator, isAdmin

func GetCacaoHeaders1

func GetCacaoHeaders1(r *http.Request) (actor service.Actor, isAdmin bool)

GetCacaoHeaders1 returns service.Actor instead of separate strings

func JSONCacaoError

func JSONCacaoError(logger *log.Entry, w http.ResponseWriter, r *http.Request, err error)

JSONCacaoError writes a JSON error response, the status code is selected based on the error type.

func JSONError

func JSONError(w http.ResponseWriter, r *http.Request, errorType string, errorMsg string, code int)

JSONError writes a JSON error response.

func ReturnStatus

func ReturnStatus(w http.ResponseWriter, obj interface{}, statusCode int)

ReturnStatus will return any "good" statuses

func StrictJSONDecode

func StrictJSONDecode(data []byte, target interface{}) error

StrictJSONDecode will take data and a target ojbect and return an error if extra json fields are not found in the target

Types

type AcceptedResponse

type AcceptedResponse struct {
	ID            string               `json:"id,omitempty"`
	TransactionID common.TransactionID `json:"tid,omitempty"`
	Timestamp     time.Time            `json:"timestamp"`
}

AcceptedResponse is used to indicate that a request has been accepted.

func NewAcceptedResponse

func NewAcceptedResponse(id common.ID, transactionID common.TransactionID) *AcceptedResponse

NewAcceptedResponse creates a new response indicating that a request has been accepted.

func NewAcceptedResponseWithStrID

func NewAcceptedResponseWithStrID(id string, transactionID common.TransactionID) *AcceptedResponse

NewAcceptedResponseWithStrID creates a new response indicating that a request has been accepted.

type ErrorStatus

type ErrorStatus struct {
	Actor     string `json:"actor"`
	Timestamp string `json:"timestamp"`
	ErrorType string `json:"error"`
	Message   string `json:"message"`
	Path      string `json:"path"`
	Verb      string `json:"verb"`
}

ErrorStatus is the struct/json object that is marshalled for every error response per CACAO's openapi spec

Jump to

Keyboard shortcuts

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