event

package
v0.0.0-...-1a88b7f Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Proof of concept for event message handlings

pkg/
└── event
    ├── message  ## Do not modify this directory, it is self-generated from schema directory
    ├── schema   ## Hold the message schemas defined
    │   ├── introspectRequest.message.yaml    ## Define schema for the message payload
    │   └── schemas.go  ## Schema loader which prepare all the necessary message schemas

Documentation

Index

Constants

View Source
const (
	// Topic constants
	TopicTodoCreated = "platform.idmsvc.todo-created"
)

Variables

View Source
var AllowedTopics = []string{
	TopicTodoCreated,
}

FIXME Refactor this to make it more dynamic and reduce work for the developer

Functions

This section is empty.

Types

type Schema

type Schema jsonschema.Schema

func LoadSchemaFromString

func LoadSchemaFromString(schema string) (*Schema, error)

LoadSchemaFromString unmarshall a schema from its string representation in json format. schemas is a string representation in json format for gojsonschema.Schema. Return the resulting list of schemas, or nil if an an error happens.

func (*Schema) Validate

func (s *Schema) Validate(data interface{}) error

Validate check that data interface accomplish the Schema. data is any type, it cannot be nil. Return nil if the check is success, else a filled error.

func (*Schema) ValidateBytes

func (s *Schema) ValidateBytes(data []byte) error

ValidateBytes validate that a slice of bytes which represent an event message match the Schema. data is a byte slice with the event message representation. Return nil if check is success, else a filled error.

type TodoCreatedEventJson

type TodoCreatedEventJson struct {
	// The Todo description
	Description string `json:"description" yaml:"description"`

	// The id of the Todo resource.
	//
	Id float64 `json:"id" yaml:"id"`

	// The Todo title
	Title string `json:"title" yaml:"title"`
}

Message schema for todo creation event

func (*TodoCreatedEventJson) UnmarshalJSON

func (j *TodoCreatedEventJson) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type TopicSchema

type TopicSchema map[string](*Schema)

func LoadSchemas

func LoadSchemas() (TopicSchema, error)

LoadSchemas unmarshall all the embedded schemas and return all them in the output schemas variable. See also LoadSchemaFromString. schemas is a hashmap map[string]*gojsonschema.Schema that can be used to immediately validate schemas against unmarshalled schemas. Return the resulting list of schemas, or nil if an an error happens.

func (*TopicSchema) GetSchema

func (ts *TopicSchema) GetSchema(topic string) *Schema

GetSchemaMap return a SchemaMap associated to one topic. topic the topic which want to retrieve the SchemaMap. Return a SchemaMap associated to the topic or nil if the topic is not found.

func (*TopicSchema) ValidateMessage

func (ts *TopicSchema) ValidateMessage(msg *kafka.Message) error

ValidateMessage check the msg is accomplish the schema defined for it. msg is a reference to a kafka.Message struct. Return nil if the check is success else an error reference is filled.

Jump to

Keyboard shortcuts

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