base

package
v0.79.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolName is the protocol name for money socket.
	ProtocolName = "Moneysocket"
	// Version is the version of the protocol.
	Version = "0.0.0"
)
View Source
const (
	// NotificationName is the name of a notification class.
	NotificationName = "NOTIFICATION"
	// RequestName is the name of a request class.
	RequestName = "REQUEST"
)
View Source
const (
	// PingRequest is a ping request.
	PingRequest MessageType = 0
	// ProviderRequest is a request for a provider.
	ProviderRequest MessageType = iota
	// InvoiceRequest is a request for an invoice.
	InvoiceRequest MessageType = iota
	// PayRequest is a request for payment.
	PayRequest MessageType = iota
	// RendezvousRequest is a request for a provider.
	RendezvousRequest MessageType = iota
	// RequestOpinionSeller requests items from an opinion seller.
	RequestOpinionSeller MessageType = iota
	// RequestOpinionInvoice creates an invoice for an opinion.
	RequestOpinionInvoice MessageType = iota

	// NotifyRendezvous notifies a rendezvous is ready.
	NotifyRendezvous = iota
	// NotifyRendezvousEndNotification notifies a rendezvous has ended.
	NotifyRendezvousEndNotification = iota
	// NotifyRendezvousNotReadyNotification notifies a rendezvous is not ready.
	NotifyRendezvousNotReadyNotification = iota
	// NotifyInvoiceNotification notifies a new invoice has come in.
	NotifyInvoiceNotification = iota
	// NotifyPreimage notifies a preimage has come in.
	NotifyPreimage = iota
	// NotifyProvider notifies a provider is ready.
	NotifyProvider = iota
	// NotifyOpinionSeller notifies an opinion seller is ready.
	NotifyOpinionSeller = iota
	// NotifyOpinionSellerNotReady notifies an opinion seller is ready.
	NotifyOpinionSellerNotReady = iota
	// NotifyProviderNotReady notifies a provider is not ready.
	NotifyProviderNotReady = iota
	// NotifyOpinionInvoice notify an opinion invoice.
	NotifyOpinionInvoice = iota
	// NotifyPing notifies a ping.
	NotifyPing = iota
	// NotifyPong notifies a pong response.
	NotifyPong = iota
)
View Source
const (
	// RequestPingName requests a ping message.
	RequestPingName = "REQUEST_PING"
	// RequestProviderName requests a provider.
	RequestProviderName = "REQUEST_PROVIDER"
	// RequestInvoiceName requests an invoice.
	RequestInvoiceName = "REQUEST_INVOICE"
	// RequestPayName requests a payment.
	RequestPayName = "REQUEST_PAY"
	// RendezvousRequestName requests a rendezvous.
	RendezvousRequestName = "REQUEST_RENDEZVOUS"
	// RequestOpinionSellerName requests an opinion seller.
	RequestOpinionSellerName = "REQUEST_OPINION_SELLER"
	// RequestOpinionInvoiceName requests an opinion invoice.
	RequestOpinionInvoiceName = "REQUEST_OPINION_INVOICE"

	// NotifyNotifyRendezvousEndName notifies a rendezvous end.
	NotifyNotifyRendezvousEndName = "NOTIFY_RENDEZVOUS_END"
	// NotifyInvoiceName notifies an invoice is ready.
	NotifyInvoiceName = "NOTIFY_INVOICE"
	// NotifyPreimageName notifies a preimage.
	NotifyPreimageName = "NOTIFY_PREIMAGE"
	// NotifyProviderName notifies a provider.
	NotifyProviderName = "NOTIFY_PROVIDER"
	// NotifyOpinionSellerName notifies a seller is ready.
	NotifyOpinionSellerName = "NOTIFY_OPINION_SELLER"
	// NotifyOpinionSellerNotReadyName notifies a seller is not ready.
	NotifyOpinionSellerNotReadyName = "NOTIFY_OPINION_SELLER_NOT_READY"
	// NotifyOpinionInvoiceName notifies an invoice.
	NotifyOpinionInvoiceName = "NOTIFY_OPINION_INVOICE"
	// NotifyProviderNotReadyName notifies a provider is not ready.
	NotifyProviderNotReadyName = "NOTIFY_PROVIDER_NOT_READY"
	// NotifyPongName notifies a pong reply.
	NotifyPongName = "NOTIFY_PONG"
	// NotifyRendezvousName notifies a rendezvous is ready.
	NotifyRendezvousName = "NOTIFY_RENDEZVOUS"
	// NotifyRendezvousNotReadyName notifies a rendezvous is not readt.
	NotifyRendezvousNotReadyName = "NOTIFY_RENDEZVOUS_NOT_READY"
)

used for.

View Source
const (
	MessageClassKey = "message_class"
)

json keys.

Variables

This section is empty.

Functions

func EncodeMoneysocketMessage

func EncodeMoneysocketMessage(msg MoneysocketMessage, toEncode map[string]interface{}) error

EncodeMoneysocketMessage maps are passed by reference by default https://bit.ly/35KrDps

Types

type MessageBase added in v0.54.0

type MessageBase struct {
	// Time is the time
	Time time.Time
	// BaseProtocol is the base protocol name
	BaseProtocol string
	// BaseProtocolVersion is the protocol version
	BaseProtocolVersion string
	// BaseMessageClass is the message class
	BaseMessageClass MessageClass
}

MessageBase is the message.

func DecodeBaseBaseMoneysocketMessage added in v0.54.0

func DecodeBaseBaseMoneysocketMessage(payload []byte) (b MessageBase, err error)

DecodeBaseBaseMoneysocketMessage decodes a moneysocket message from json.

func NewBaseBaseMoneysocketMessage added in v0.54.0

func NewBaseBaseMoneysocketMessage(messageType MessageClass) MessageBase

NewBaseBaseMoneysocketMessage creates a new MessageBase from a given MessageClass.

func (MessageBase) CryptLevel added in v0.54.0

func (m MessageBase) CryptLevel() string

CryptLevel is the cryptography level of the message this can be override in the sub-class.

func (MessageBase) IsValid added in v0.54.0

func (m MessageBase) IsValid() (bool, error)

IsValid determines wether or not a message is valid this is implemented in a sub-class.

func (MessageBase) MessageClass added in v0.54.0

func (m MessageBase) MessageClass() MessageClass

MessageClass returns the MessageClass of the message.

func (MessageBase) MustBeClearText added in v0.54.0

func (m MessageBase) MustBeClearText() bool

MustBeClearText determines whether or not a message can be unencrypted this can be overrided in the message class.

func (MessageBase) Protocol added in v0.54.0

func (m MessageBase) Protocol() string

Protocol is the protocol of the message.

func (MessageBase) ProtocolVersion added in v0.54.0

func (m MessageBase) ProtocolVersion() string

ProtocolVersion determines the version of MessageBase.

func (MessageBase) Timestamp added in v0.54.0

func (m MessageBase) Timestamp() time.Time

Timestamp is the timestamp fo the message.

func (MessageBase) ToJSON added in v0.54.0

func (m MessageBase) ToJSON() ([]byte, error)

ToJSON marshals the message to json.

type MessageClass

type MessageClass int

MessageClass is a type used to determine a message class.

const (
	// Notification is the MessageClass of the Notification.
	Notification MessageClass = 0
	// Request is the MessageClass of the Request.
	Request MessageClass = iota
)

func MessageClassFromString

func MessageClassFromString(class string) MessageClass

MessageClassFromString determines the MessageClass from a given string.

func (MessageClass) ToString

func (m MessageClass) ToString() string

ToString converts a message class to the string (either NotificationName or RequestName).

type MessageType

type MessageType int

MessageType is the message or notification type.

func MessageTypeFromString

func MessageTypeFromString(name string) MessageType

MessageTypeFromString converts a name to a MessageType.

func (MessageType) ToString

func (r MessageType) ToString() string

ToString converts a message to a string.

type MoneysocketMessage

type MoneysocketMessage interface {
	// get timestamp message was created
	Timestamp() time.Time
	// get protocol
	Protocol() string
	// get protocol version
	ProtocolVersion() string
	// get message class (request or message)
	MessageClass() MessageClass
	// convert a message to json
	ToJSON() ([]byte, error)
	// wetrher or not the message is valid
	IsValid() (bool, error)
	// wether or not a message must be clear text
	MustBeClearText() bool
	// encryption level
	CryptLevel() string
}

MoneysocketMessage is probably one of the worst ways to handle json in go but I wanted to make sure the first vresion was as close to moneysocket as possible architecturally so I could safely refactor with test cases in place.

Jump to

Keyboard shortcuts

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