Documentation ¶
Index ¶
- func DialSmtpServer(server, username, password string) (*smtp.Client, error)
- func WriteCacheableJSONResponse(w http.ResponseWriter, req *http.Request, value any)
- func WriteJSONErrorResponse(w http.ResponseWriter, aerr ActionError, status int, details ...string)
- func WriteJSONResponse(w http.ResponseWriter, value any)
- func WriteJSONResponseWithStatus(w http.ResponseWriter, status int, value any)
- type ActionError
- type ErrorResponse
- type NotAllowedHandler
- type NotFoundHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DialSmtpServer ¶ added in v0.0.2
DialSmtpServer dials an SMTP server and returns a configured client. It supports both insecure and TLS access. In case the port in the "server" value is 25 (e.g. "localhost:25") then the insecure variant is used. For other port values, the function tries to handle TLS connection.
func WriteCacheableJSONResponse ¶
func WriteCacheableJSONResponse(w http.ResponseWriter, req *http.Request, value any)
WriteCacheableJSONResponse writes 'value' to an HTTP response encoded as JSON but before doing that it calculates a checksum of the JSON and in case it is equal to provided 'If-Match' header, 304 is returned. Otherwise a value with ETag header is returned.
func WriteJSONErrorResponse ¶
func WriteJSONErrorResponse(w http.ResponseWriter, aerr ActionError, status int, details ...string)
WriteJSONErrorResponse writes 'aerr' to an HTTP error response as JSON
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, value any)
WriteJSONResponse writes 'value' to an HTTP response encoded as JSON
func WriteJSONResponseWithStatus ¶
func WriteJSONResponseWithStatus(w http.ResponseWriter, status int, value any)
WriteJSONResponseWithStatus writes 'value' to an HTTP response encoded as JSON
Types ¶
type ActionError ¶
type ActionError struct {
// contains filtered or unexported fields
}
ActionError represents a basic user action error (e.g. a wrong parameter, non-existing record etc.)
func NewActionError ¶
func NewActionError(msg string, args ...any) ActionError
NewActionError creates an Action error from provided message using a newly defined general error as the original error
func NewActionErrorFrom ¶
func NewActionErrorFrom(err error) ActionError
func (ActionError) MarshalJSON ¶
func (me ActionError) MarshalJSON() ([]byte, error)
MarshalJSON serializes the error to JSON
type ErrorResponse ¶
type ErrorResponse struct { Error *ActionError `json:"error"` Details []string `json:"details"` Code int `json:"code"` }
ErrorResponse describes a wrapping object for all error HTTP responses
type NotAllowedHandler ¶ added in v0.0.3
type NotAllowedHandler struct { }
func (NotAllowedHandler) ServeHTTP ¶ added in v0.0.3
func (handler NotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type NotFoundHandler ¶ added in v0.0.3
type NotFoundHandler struct { }
func (NotFoundHandler) ServeHTTP ¶ added in v0.0.3
func (handler NotFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)