Documentation ¶
Index ¶
- Variables
- type Config
- type Message
- type Service
- func (s *Service) BuildRequest(payload map[string]interface{}) (map[string]interface{}, error)
- func (s *Service) BuildSignedRequest(payload map[string]interface{}) ([]byte, error)
- func (s *Service) Notify(selfID, content string) error
- func (s *Service) Request(recipients []string, req []byte) ([]byte, error)
- func (s *Service) Respond(recipient, conversationID string, response []byte) error
- func (s *Service) Send(recipients []string, conversationID string, body []byte) error
- func (s *Service) SendAsync(recipients []string, conversationID string, body []byte, ...)
- func (s *Service) Start() bool
- func (s *Service) Subscribe(messageType string, h func(m *Message))
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadJSONPayload = errors.New("bad json payload") ErrResponseBadSignature = errors.New("bad response signature") ErrRequestTimeout = errors.New("request timeout") ErrMessageBadIssuer = errors.New("bad response issuer") ErrMessageBadAudience = errors.New("bad response audience") ErrMessageBadStatus = errors.New("bad response status") ErrMessageExpired = errors.New("response has expired") ErrMessageIssuedTooSoon = errors.New("response was issued in the future") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { SelfID string DeviceID string KeyID string PrivateKey ed25519.PrivateKey PKI pkiClient Messaging messagingClient Rest restTransport }
Config stores all configuration needed by the messaging service
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles all messaging operations
func NewService ¶
NewService creates a new client for interacting with messaging
func (*Service) BuildRequest ¶
BuildRequest constructs a request map based on the given payload and returns it along with an error. - payload (map[string]interface{}): the payload to include in the request Returns: - (map[string]interface{}): the constructed request map - (error): an error if the "typ" key is not present in the request map
func (*Service) BuildSignedRequest ¶
BuildSignedRequest creates a request payload with the given payload, and returns the payload as a byte array. It generates a new request ID, JWT ID, and timestamps for the request. If the payload does not contain a "typ" key, it returns an empty byte array and an error. If the payload contains a "sub" key but not an "aud" key, it sets the "aud" key to the value of "sub". It then calls the PrepareJWS function to prepare a JWS token with the request payload, and returns the JWS token as a byte array.
Parameters:
- payload: A map of string keys to interface{} values representing the payload of the request.
Returns:
- []byte: A byte array representing the prepared JWS token.
- error: An error that is non-nil if the payload does not contain a "typ" key.