Documentation

Index

Constants

View Source
const (
	ChannelInvalid = uint8(iota)
	ChannelStatic
	ChannelWildcard
)

    Channel types

    View Source
    const (
    	MinTime = 1514764800 // 2018
    	MaxTime = 3029529600 // 2066
    )

      Minimum and maximum unix time stamp we can handle for options

      View Source
      const (
      	AllowNone      = uint8(0)                     // Key has no privileges.
      	AllowMaster    = uint8(1 << 0)                // Key should be allowed to generate other keys.
      	AllowRead      = uint8(1 << 1)                // Key should be allowed to subscribe to the target channel.
      	AllowWrite     = uint8(1 << 2)                // Key should be allowed to publish to the target channel.
      	AllowStore     = uint8(1 << 3)                // Key should be allowed to write to the message history of the target channel.
      	AllowLoad      = uint8(1 << 4)                // Key should be allowed to write to read the message history of the target channel.
      	AllowPresence  = uint8(1 << 5)                // Key should be allowed to query the presence on the target channel.
      	AllowExtend    = uint8(1 << 6)                // Key should be allowed to create sub-channels by extending an existing one.
      	AllowExecute   = uint8(1 << 7)                // Key should be allowed to execute code. (RESERVED)
      	AllowReadWrite = AllowRead | AllowWrite       // Key should be allowed to read and write to the target channel.
      	AllowStoreLoad = AllowStore | AllowLoad       // Key should be allowed to read and write the message history.
      	AllowAll       = math.MaxUint8 &^ AllowMaster // Key allows everything except master
      )

        Access types for a security key.

        Variables

        View Source
        var (
        	ErrTargetInvalid = errors.New("channel should end with `/` for strict types or `/#/` for multi level wildcard")
        	ErrTargetTooLong = errors.New("channel can not have more than 23 parts")
        )

          Key errors

          Functions

          This section is empty.

          Types

          type Channel

          type Channel struct {
          	Key         []byte          // Gets or sets the API key of the channel.
          	Channel     []byte          // Gets or sets the channel string.
          	Query       []uint32        // Gets or sets the full ssid.
          	Options     []ChannelOption // Gets or sets the options.
          	ChannelType uint8
          }

            Channel represents a parsed MQTT topic.

            func MakeChannel

            func MakeChannel(key, channelWithOptions string) *Channel

              MakeChannel attempts to parse the channel from the key and channel strings.

              func ParseChannel

              func ParseChannel(text []byte) (channel *Channel)

                ParseChannel attempts to parse the channel from the underlying slice.

                func (*Channel) Exclude

                func (c *Channel) Exclude() bool

                  Exclude returns whether the exclude me ('me=0') option was set or not.

                  func (*Channel) Last

                  func (c *Channel) Last() (int64, bool)

                    Last returns the 'last' option, which is a number of messages to retrieve.

                    func (*Channel) SafeString

                    func (c *Channel) SafeString() string

                      SafeString returns a string representation of the channel without the key.

                      func (*Channel) String

                      func (c *Channel) String() string

                        String returns a string representation of the channel.

                        func (*Channel) TTL

                        func (c *Channel) TTL() (int64, bool)

                          TTL returns a Time-To-Live option.

                          func (*Channel) Target

                          func (c *Channel) Target() uint32

                            Target returns the channel target (first element of the query, second element of an SSID)

                            func (*Channel) Window

                            func (c *Channel) Window() (time.Time, time.Time)

                              Window returns the from-until options which should be a UTC unix timestamp in seconds.

                              type ChannelOption

                              type ChannelOption struct {
                              	Key   string
                              	Value string
                              }

                                ChannelOption represents a key/value pair option.

                                type ID

                                type ID uint64

                                  ID represents a process-wide unique ID.

                                  func NewID

                                  func NewID() ID

                                    NewID generates a new, process-wide unique ID.

                                    func (ID) String

                                    func (id ID) String() string

                                      String converts the ID to a string representation.

                                      func (ID) Unique

                                      func (id ID) Unique(prefix uint64, salt string) string

                                        Unique generates unique id based on the current id with a prefix and salt.

                                        type Key

                                        type Key []byte

                                          Key represents a security key.

                                          func (Key) Contract

                                          func (k Key) Contract() uint32

                                            Contract gets the contract id.

                                            func (Key) Expires

                                            func (k Key) Expires() time.Time

                                              Expires gets the expiration date for the key.

                                              func (Key) HasPermission

                                              func (k Key) HasPermission(flag uint8) 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) IsExpired

                                                  func (k Key) IsExpired() bool

                                                    IsExpired gets whether the key has expired or not.

                                                    func (Key) IsMaster

                                                    func (k Key) IsMaster() bool

                                                      IsMaster gets whether the key is a master key..

                                                      func (Key) Master

                                                      func (k Key) Master() uint16

                                                        Master gets the master key id.

                                                        func (Key) Permissions

                                                        func (k Key) Permissions() uint8

                                                          Permissions gets the permission flags.

                                                          func (Key) Salt

                                                          func (k Key) Salt() uint16

                                                            Salt gets the random salt of the key

                                                            func (Key) SetContract

                                                            func (k Key) SetContract(value uint32)

                                                              SetContract sets the contract id.

                                                              func (Key) SetExpires

                                                              func (k Key) SetExpires(value time.Time)

                                                                SetExpires sets the expiration date for the key.

                                                                func (Key) SetMaster

                                                                func (k Key) SetMaster(value uint16)

                                                                  SetMaster sets the master key id.

                                                                  func (Key) SetPermission

                                                                  func (k Key) SetPermission(flag uint8, value bool)

                                                                    SetPermission sets a permission to a value

                                                                    func (Key) SetPermissions

                                                                    func (k Key) SetPermissions(value uint8)

                                                                      SetPermissions sets the permission flags.

                                                                      func (Key) SetSalt

                                                                      func (k Key) SetSalt(value uint16)

                                                                        SetSalt sets the random salt of the key.

                                                                        func (Key) SetSignature

                                                                        func (k Key) SetSignature(value uint32)

                                                                          SetSignature sets the signature of the contract.

                                                                          func (Key) SetTarget

                                                                          func (k Key) SetTarget(channel string) error

                                                                            SetTarget sets the target channel for the key.

                                                                            func (Key) Signature

                                                                            func (k Key) Signature() uint32

                                                                              Signature gets the signature of the contract.

                                                                              func (Key) ValidateChannel

                                                                              func (k Key) ValidateChannel(ch *Channel) bool

                                                                                ValidateChannel validates the channel string.

                                                                                Directories

                                                                                Path Synopsis