cel

package module
v0.0.0-...-fe0c958 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 4 Imported by: 0

README

go-cel

Package cel provide tools for creating software that models systems based on Commands, Events, and Logs.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-cel

GoDoc

Quick Example

Here is a quick example:

const apiVersion string = "1"

c := cel_message.Command(
		apiVersion,
		"LOCK_DOOR",
		map[string]interface{}{
			"from":"john",
			"doorid":"abc123",
		},
)

e := cel_message.Event(
		apiVersion,
		"DOOR_LOCKED",
		map[string]interface{}{
			"from":"jane",
			"doorid":"abc123",
		},
)

l := cel_message.Log(
		apiVersion,
		"DOORS",
		map[string]interface{}{
			"doors": []map[string]interface{}{
				map[string]interface{}{
					"doorid":"abc123",
					"is_locked":true,
				},
				map[string]interface{}{
					"doorid":"def456",
					"is_locked":false,
				},
				map[string]interface{}{
					"doorid":"ghi789",
					"is_locked":false,
				},
			},
		},
)

You could then send this over some transport, such as a websocket, or message queue, IP over avian carriers, or whatever.

You could also receive a CEL message with code similar to the following:

var msg cel_mesage.Type

err := json.Unmarshal(data, &msg)

Messages

Collectively we call commands, events, and logs: messages.

Each message has:

  • magic
  • version
  • kind
  • name
  • payload

(Note that ‘magic’ is hidden.)

In the code, (using the Go proscribed style of naming interfaces) a message is represented as a:

cel.Messenger

A `cel.Messenger`` has the following methods:

  • cel.Messenger.Version()
  • cel.Messenger.Kind()
  • cel.Messenger.Name()
  • cel.Messenger.Payload()

In addition to cel.Messenger, this package provides an implementation of cel.Messenger with the struct:

cel_message.Type

JSON

cel_message.Type supports marshaling and unmarshaling to and from JSON.

The serialized JSON will look like:

An example command:

{
	"magic"   : "CEL/1",
	"version" : "1",
	"kind"    : "EVENT",
	"name"    : "LOCK_DOOR",
	"payload" : {
		"from":"john",
		"doorid":"abc123",
	},
}

An example event:

{
	"magic"   : "CEL/1",
	"version" : "1",
	"kind"    : "EVENT",
	"name"    : "DOOR_LOCKED",
	"payload" : {
		"from":"jane",
		"doorid":"abc123",
	},
}

An example log:

{
	"magic"   : "CEL/1",
	"version" : "1",
	"kind"    : "LOG",
	"name"    : "DOORS",
	"payload" : {
		"doors": [
			{
				"doorid":"abc123",
				"is_locked":true,
			},
			{
				"doorid":"def456",
				"is_locked":false,
			},
			{
				"doorid":"ghi789",
				"is_locked":false,
			},
		],
	},
}

"magic" is (for now) always "CEL/1".

"version" can be set to whatever you want it to be. It is a means for your to (future-proof yourself and) version your API. (If you aren't sure what to set for this, just use (the string value) "1".)

The only valid values for "kind" are "COMMAND", "EVENT", and "LOG".

You will come up with the values of "name".

And the value of "payload" is dependent on what the value for "name" is.

See Also

A similar library has also been created for JavaScript:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Messenger

type Messenger interface {
	Version() cel_version.Type
	Kind() cel_kind.Type
	Name() cel_name.Type
	Payload() cel_payload.Payloader
}

Messenger represents a message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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