publish

package
v0.0.0-...-a52e8f6 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FieldData value
	FieldData = "data"
	// FieldEventID value
	FieldEventID = "event-id"
	// FieldEventTime value
	FieldEventTime = "event-time"
	// FieldEventType value
	FieldEventType = "event-type"
	// FieldEventTypeVersion value
	FieldEventTypeVersion = "event-type-version"
	// FieldSourceID value
	FieldSourceID = "source-id"
	// FieldTraceContext value
	FieldTraceContext = "trace-context"

	// AllowedEventIDChars regex
	AllowedEventIDChars = `^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$`

	// AllowedSourceIDChars regex
	AllowedSourceIDChars = `^[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?)*$`
	// AllowedEventTypeChars regex
	AllowedEventTypeChars = `^[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([-a-zA-Z0-9]*[a-zA-Z0-9])?)*$`
	// AllowedEventTypeVersionChars regex
	AllowedEventTypeVersionChars = `^[a-zA-Z0-9]+$`

	// HeaderSourceID heaver
	HeaderSourceID = "Source-Id"
)
View Source
const (
	/*ErrorTypeBadPayload The request payload has incorrect syntax according to the sent Content-Type.
	Check the payload content for syntax errors, such as missing commas or quotation marks that are not closed.
	*/
	ErrorTypeBadPayload = "bad_payload_syntax"
	/*ErrorTypeValidationViolation Top level validation error.
	 */
	ErrorTypeValidationViolation = "validation_violation"
	/*ErrorTypeMissingField Sub-level error type of `ErrorTypeValidationViolation` representaing that the requested body
	payload for a POST or PUT operation is missing,	which violates the defined validation constraints. This denotes
	a missing field when a value is expected.
	*/
	ErrorTypeMissingField = "missing_field"

	// ErrorTypeMissingFieldOrHeader error type for a missing field or header.
	ErrorTypeMissingFieldOrHeader = "missing_field/missing_header"
	/*ErrorTypeInvalidField Sub-level error type of `ErrorTypeValidationViolation` representaing that the requested body
	payload for the POST or PUT operation violates the validation constraints.
	This denotes specifically that there is:
	- A type incompatibility, such as a field modeled to be an integer, but a non-numeric expression was found instead.
	- A range under or over flow validation violation cause.
	*/
	ErrorTypeInvalidField = "invalid_field"
	// ErrorTypeInvalidHeader is error type code for invalid header
	ErrorTypeInvalidHeader = "invalid_header"
	// ErrorTypeInvalidFieldLength is error type code for invalid field length
	ErrorTypeInvalidFieldLength = "invalid_field_length"
	// ErrorTypeRequestBodyTooLarge is error type code for error responses where request body is too large
	ErrorTypeRequestBodyTooLarge = "request_body_too_large"
	// ErrorMessageRequestBodyTooLarge is error message for error responses where request body is too large
	ErrorMessageRequestBodyTooLarge = "Request body too large"
	// ErrorTypeInternalServerError Some unexpected internal error occurred while processing the request.
	ErrorTypeInternalServerError = "internal_server_error"
	// ErrorMessageInternalServerError represents the error message for `ErrorTypeInternalServerError`
	ErrorMessageInternalServerError = "Some unexpected internal error occurred, please contact support."
	/*ErrorTypeBadRequest A generic error for bad requests sent by the clients. Use when none of the specific
	error types apply.
	*/
	ErrorTypeBadRequest = "bad_request"
	// ErrorMessageBadRequest represents the error message for `ErrorTypeBadRequest`
	ErrorMessageBadRequest = "Some unexpected internal error occurred, please contact support."
	// ErrorMessageBadPayload represents the error message for `ErrorTypeBadPayload`
	ErrorMessageBadPayload = "Something went very wrong. Please try again."
	// ErrorMessageMissingField represents the error message for `ErrorTypeMissingField`
	ErrorMessageMissingField = "We need all required fields complete to keep you moving."
	// ErrorMessageInvalidField represents the error message for `ErrorTypeInvalidField`
	ErrorMessageInvalidField = "We need all your entries to be correct to keep you moving."
	// ErrorMessageInvalidFieldLength represents the error message for `ErrorTypeInvalidFieldLength`
	ErrorMessageInvalidFieldLength = "Field length must be at max: %d"
	// ErrorMessageMissingSourceID represents the error message for `ErrorTypeMissingFieldOrHeader`
	ErrorMessageMissingSourceID = "Either provide 'Source-Id' header or specify 'source-id' in the json payload"
)
View Source
const (
	// DefaultMaxSourceIDLength default value
	DefaultMaxSourceIDLength = 253
	// DefaultMaxEventTypeLength default value
	DefaultMaxEventTypeLength = 253
	// DefaultMaxEventTypeVersionLength default value
	DefaultMaxEventTypeVersionLength = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyValue

type AnyValue interface{}

AnyValue implements the service definition of AnyValue

type CloudEvent

type CloudEvent struct {
	Request
	Extensions Extensions `json:"extensions,omitempty"`
}

CloudEvent represents the event to be persisted to NATS

type Error

type Error struct {
	Status   int           `json:"status"`
	Type     string        `json:"type"`
	Message  string        `json:"message"`
	MoreInfo string        `json:"moreInfo"`
	Details  []ErrorDetail `json:"details"`
}

Error represents API error response code

func CreateInvalidFieldError

func CreateInvalidFieldError(field interface{}) (response *Error)

CreateInvalidFieldError creates an Error for an invalid field

func CreateMissingFieldError

func CreateMissingFieldError(field interface{}) (response *Error)

CreateMissingFieldError creates an Error for a missing field

func ErrorInvalidEventTypeLength

func ErrorInvalidEventTypeLength(eventTypeMaxLength int) *Error

ErrorInvalidEventTypeLength creates an API Error response in case Event Type length exceeded the maximum

func ErrorInvalidEventTypeVersionLength

func ErrorInvalidEventTypeVersionLength(eventTypeVersionMaxLength int) *Error

ErrorInvalidEventTypeVersionLength creates an API Error response in case Event Type Version length exceeded the maximum

func ErrorInvalidFieldLength

func ErrorInvalidFieldLength(field string, length int) *Error

ErrorInvalidFieldLength returns an API error instance for the invalid field length error.

func ErrorInvalidSourceIDLength

func ErrorInvalidSourceIDLength(sourceIDMaxLength int) *Error

ErrorInvalidSourceIDLength creates an API Error response in case Source ID length exceeded the maximum

func ErrorResponseBadPayload

func ErrorResponseBadPayload() (response *Error)

ErrorResponseBadPayload returns an API error instance for the bad payload error.

func ErrorResponseBadRequest

func ErrorResponseBadRequest() (response *Error)

ErrorResponseBadRequest returns an API error instance for the bad request error.

func ErrorResponseInternalServer

func ErrorResponseInternalServer() (response *Error)

ErrorResponseInternalServer creates API Error response for case of internal server error.

func ErrorResponseMissingFieldData

func ErrorResponseMissingFieldData() (response *Error)

ErrorResponseMissingFieldData returns an API error instance for the missing field data error.

func ErrorResponseMissingFieldEventTime

func ErrorResponseMissingFieldEventTime() (response *Error)

ErrorResponseMissingFieldEventTime returns an API error instance for the missing field event time error.

func ErrorResponseMissingFieldEventType

func ErrorResponseMissingFieldEventType() (response *Error)

ErrorResponseMissingFieldEventType returns an API error instance for the missing field event type error.

func ErrorResponseMissingFieldEventTypeVersion

func ErrorResponseMissingFieldEventTypeVersion() (response *Error)

ErrorResponseMissingFieldEventTypeVersion returns an API error instance for the missing field event type version error.

func ErrorResponseMissingFieldSourceID

func ErrorResponseMissingFieldSourceID() (response *Error)

ErrorResponseMissingFieldSourceID returns an API error instance for the missing field source ID error.

func ErrorResponseRequestBodyTooLarge

func ErrorResponseRequestBodyTooLarge() (response *Error)

ErrorResponseRequestBodyTooLarge creates API Error response for case of request body being too large

func ErrorResponseWrongEventID

func ErrorResponseWrongEventID() (response *Error)

ErrorResponseWrongEventID returns an API error instance for the wrong event ID error.

func ErrorResponseWrongEventTime

func ErrorResponseWrongEventTime() (response *Error)

ErrorResponseWrongEventTime returns an API error instance for the wrong event time error.

func ErrorResponseWrongEventType

func ErrorResponseWrongEventType() (response *Error)

ErrorResponseWrongEventType returns an API error instance for the wrong event type error.

func ErrorResponseWrongEventTypeVersion

func ErrorResponseWrongEventTypeVersion() (response *Error)

ErrorResponseWrongEventTypeVersion returns an API error instance for the wrong event type version error.

func ErrorResponseWrongSourceID

func ErrorResponseWrongSourceID(sourceIDFromHeader bool) (response *Error)

ErrorResponseWrongSourceID returns an API error instance for the wrong source ID error.

type ErrorDetail

type ErrorDetail struct {
	Field    string `json:"field"`
	Type     string `json:"type"`
	Message  string `json:"message"`
	MoreInfo string `json:"moreInfo"`
}

ErrorDetail represents error cause

type EventOptions

type EventOptions struct {
	MaxSourceIDLength         int
	MaxEventTypeLength        int
	MaxEventTypeVersionLength int
}

EventOptions represents the event options.

func GetDefaultEventOptions

func GetDefaultEventOptions() *EventOptions

GetDefaultEventOptions returns a new default event options instance.

type Extensions

type Extensions = map[string]interface{}

Extensions type

type Request

type Request struct {
	SourceID           string   `json:"source-id"`
	EventType          string   `json:"event-type"`
	EventTypeVersion   string   `json:"event-type-version"`
	EventID            string   `json:"event-id"`
	EventTime          string   `json:"event-time"`
	Data               AnyValue `json:"data"`
	SourceIDFromHeader bool
}

Request represents a publish request

type Response

type Response struct {
	EventID string `json:"event-id"`
	Status  string `json:"status"`
	Reason  string `json:"reason"`
}

Response represents a successful publish response

type TraceContext

type TraceContext map[string]string

TraceContext type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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