Version: v0.0.0-...-53883ab Latest Latest

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 5 Imported by: 12




View Source
const (
	AllowNone      = uint32(0)              // Key has no privileges.
	AllowRead      = uint32(1 << 1)         // Key should be allowed to subscribe to the topic.
	AllowWrite     = uint32(1 << 2)         // Key should be allowed to publish to the topic.
	AllowReadWrite = AllowRead | AllowWrite // Key should be allowed to read and write to the topic.

	// Topic types
	TopicInvalid = uint8(iota)

	TopicKeySeparator = '/'
	TopicSeparator    = '.' // The separator character.


Access types for a security key.


View Source
var (
	ErrTargetTooLong = errors.New("topic can not have more than 23 parts")

Key errors


func GenerateKey

func GenerateKey(contract uint32, topic []byte, permissions uint32) (string, error)

GenerateKey generates a new key.


type Key

type Key []byte

Key represents a security key.

func DecodeKey

func DecodeKey(key []byte) (Key, error)

func (Key) Encode

func (k Key) Encode() string

func (Key) HasPermission

func (k Key) HasPermission(flag uint32) bool

HasPermission check whether the key provides some permission.

func (Key) IsEmpty

func (k Key) IsEmpty() bool

IsEmpty checks whether the key is empty or not.

func (Key) Permissions

func (k Key) Permissions() uint32

Permissions gets the permission flags.

func (Key) SetPermissions

func (k Key) SetPermissions(value uint32)

SetPermissions sets the permission flags.

func (Key) SetTarget

func (k Key) SetTarget(contract uint32, topic []byte) error

SetTarget sets the topic for the key.

func (Key) ValidateTopic

func (k Key) ValidateTopic(contract uint32, topic []byte) (ok bool, wildcard bool)

ValidateTopic validates the topic string.

type Topic

type Topic struct {
	Key       []byte // Gets or sets the API key of the topic.
	Topic     []byte // Gets or sets the topic string.
	TopicType uint8
	Size      int // Topic size without options

Topic represents a parsed topic.

func ParseKey

func ParseKey(text []byte) (topic *Topic)

ParseKey attempts to parse the key

func (*Topic) Target

func (topic *Topic) Target() uint32

Target returns the topic (first element of the query, second element of an parts)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL