syftmsg

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMessageExpiry is the default time in seconds before a message expires
	// 1 day
	DefaultMessageExpiry = 24 * 60 * 60 * time.Second

	// HTTP Methods
	MethodGET    SyftMethod = "GET"
	MethodPOST   SyftMethod = "POST"
	MethodPUT    SyftMethod = "PUT"
	MethodDELETE SyftMethod = "DELETE"

	// Status codes
	StatusOK SyftStatus = 200
)
View Source
const IdSize = 3

Variables

This section is empty.

Functions

This section is empty.

Types

type Ack

type Ack struct{}

type Error

type Error struct {
	Code    int    `json:"cod"`
	Path    string `json:"pth"`
	Message string `json:"msg"`
}

type FileDelete

type FileDelete struct {
	Path string `json:"pth"`
}

type FileWrite

type FileWrite struct {
	Path    string `json:"pth"`
	ETag    string `json:"etg"`
	Length  int64  `json:"len"`
	Content []byte `json:"con,omitempty"`
}

type HttpMsg added in v0.6.0

type HttpMsg struct {
	From    string            `json:"from"`
	SyftURL utils.SyftBoxURL  `json:"syft_url"`
	Method  string            `json:"method"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    []byte            `json:"body,omitempty"`
	Id      string            `json:"id"`
	Etag    string            `json:"etag,omitempty"`
}

type HttpMsgType added in v0.6.0

type HttpMsgType string
const (
	HttpMsgTypeRequest  HttpMsgType = "request"
	HttpMsgTypeResponse HttpMsgType = "response"
)

type Message

type Message struct {
	Id   string      `json:"id"`
	Type MessageType `json:"typ"`
	Data any         `json:"dat"`
}

func NewAck

func NewAck(id string) *Message

func NewError

func NewError(code int, path string, msg string) *Message

func NewFileDelete

func NewFileDelete(path string) *Message

func NewFileWrite

func NewFileWrite(path string, etag string, length int64, contents []byte) *Message

func NewHttpMsg added in v0.6.0

func NewHttpMsg(
	from string,
	syftURL utils.SyftBoxURL,
	method string,
	body []byte,
	headers map[string]string,
	id string,
	etag string,
) *Message

func NewNack

func NewNack(id string, err string) *Message

func NewSystemMessage

func NewSystemMessage(version string, msg string) *Message

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Message

type MessageType

type MessageType uint16
const (
	MsgSystem MessageType = iota
	MsgError
	MsgFileWrite
	MsgFileDelete
	MsgAck
	MsgNack
	MsgHttp
)

func (MessageType) String

func (t MessageType) String() string

type Nack

type Nack struct {
	Error string `json:"err"`
}

type SyftMethod added in v0.6.0

type SyftMethod string

SyftMethod represents the HTTP method in the Syft protocol

func (SyftMethod) IsValid added in v0.6.0

func (m SyftMethod) IsValid() bool

IsValid checks if the method is valid

func (SyftMethod) Validate added in v0.6.0

func (m SyftMethod) Validate() error

Validate validates the method

type SyftRPCMessage added in v0.6.0

type SyftRPCMessage struct {
	// ID is the unique identifier of the message
	ID uuid.UUID `json:"id"`

	// Sender is the sender of the message
	Sender string `json:"sender"`

	// URL is the URL of the message
	URL utils.SyftBoxURL `json:"url"`

	// Body is the body of the message in bytes
	Body []byte `json:"body,omitempty"`

	// Headers contains additional headers for the message
	Headers map[string]string `json:"headers"`

	// Created is the timestamp when the message was created
	Created time.Time `json:"created"`

	// Expires is the timestamp when the message expires
	Expires time.Time `json:"expires"`

	Method SyftMethod `json:"method,omitempty"`

	StatusCode SyftStatus `json:"status_code,omitempty"`
}

SyftMessage represents a base message for Syft protocol communication

func NewSyftRPCMessage added in v0.6.0

func NewSyftRPCMessage(
	sender string, url utils.SyftBoxURL, method SyftMethod, body []byte, headers map[string]string,
) (*SyftRPCMessage, error)

NewSyftMessage creates a new SyftMessage with default values

func (*SyftRPCMessage) MarshalJSON added in v0.6.0

func (m *SyftRPCMessage) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to handle bytes as base64

func (*SyftRPCMessage) ToJsonMap added in v0.6.0

func (m *SyftRPCMessage) ToJsonMap() map[string]interface{}

JSONString returns a properly formatted JSON string with decoded body

func (*SyftRPCMessage) UnmarshalJSON added in v0.6.0

func (m *SyftRPCMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling to handle base64 encoded body

func (*SyftRPCMessage) Validate added in v0.6.0

func (m *SyftRPCMessage) Validate() error

Validate validates the message

type SyftStatus added in v0.6.0

type SyftStatus int

SyftStatus represents the status code in the Syft protocol

func (SyftStatus) IsValid added in v0.6.0

func (s SyftStatus) IsValid() bool

IsValid checks if the status code is valid

func (SyftStatus) Validate added in v0.6.0

func (s SyftStatus) Validate() error

Validate validates the status code

type System

type System struct {
	SystemVersion string `json:"ver"`
	Message       string `json:"msg"`
}

type ValidationError added in v0.6.0

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a validation error

func (*ValidationError) Error added in v0.6.0

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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