send

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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTimeout        = "timeout"
	ErrorInvalidRequest = "invalid_request"
	ErrorInternal       = "internal_error"
	ErrorNotFound       = "not_found"
	PollURL             = "/api/v1/send/poll?x-syft-request-id=%s&x-syft-url=%s&x-syft-from=%s&x-syft-raw=%t"
)

Error constants

Variables

View Source
var (
	ErrPollTimeout     = errors.New("poll timeout")
	ErrRequestNotFound = errors.New("request not found")
)
View Source
var (
	ErrMsgNotFound = errors.New("message not found")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Error     string `json:"error"`
	Message   string `json:"message"`
	RequestID string `json:"request_id,omitempty"`
}

APIError represents a standardized error response

type APIResponse

type APIResponse struct {
	RequestID string      `json:"request_id"`
	Data      interface{} `json:"data,omitempty"`
	Message   string      `json:"message,omitempty"`
}

APIResponse represents a standardized success response

type BlobMsgStore

type BlobMsgStore struct {
	// contains filtered or unexported fields
}

func (*BlobMsgStore) DeleteMsg

func (m *BlobMsgStore) DeleteMsg(ctx context.Context, path string) error

func (*BlobMsgStore) GetMsg

func (m *BlobMsgStore) GetMsg(ctx context.Context, path string) (io.ReadCloser, error)

func (*BlobMsgStore) StoreMsg

func (m *BlobMsgStore) StoreMsg(ctx context.Context, path string, msgBytes []byte) error

type Config

type Config struct {
	DefaultTimeout      time.Duration
	MaxTimeout          time.Duration
	ObjectPollInterval  time.Duration
	RequestCheckTimeout time.Duration
	MaxBodySize         int64
}

Config holds the service configuration

type Headers

type Headers map[string]string

type MessageDispatcher

type MessageDispatcher interface {
	Dispatch(datasite string, msg *syftmsg.Message) bool
}

Message dispatch interface for dispatching messages to users

func NewWSMsgDispatcher

func NewWSMsgDispatcher(hub *ws.WebsocketHub) MessageDispatcher

type MessageRequest

type MessageRequest struct {
	SyftURL utils.SyftBoxURL `form:"x-syft-url" binding:"required"`  // Binds to the syft url using UnmarshalParam
	From    string           `form:"x-syft-from" binding:"required"` // The sender of the message
	Timeout int              `form:"timeout" binding:"gte=0"`        // The timeout for the request in milliseconds
	AsRaw   bool             `form:"x-syft-raw" default:"false"`     // If true, the request body will be read and sent as is
	Method  string           // Will be set from request method
	Headers Headers          // Will be set from request headers
}

MessageRequest represents the request for sending a message

func (*MessageRequest) BindHeaders

func (h *MessageRequest) BindHeaders(ctx *gin.Context)

type PollInfo

type PollInfo struct {
	PollURL string `json:"poll_url"`
}

type PollObjectRequest

type PollObjectRequest struct {
	RequestID string           `form:"x-syft-request-id" binding:"required"`
	From      string           `form:"x-syft-from" binding:"required"`
	SyftURL   utils.SyftBoxURL `form:"x-syft-url" binding:"required"`
	Timeout   int              `form:"timeout,omitempty" binding:"gte=0"` // Timeout in milliseconds
	UserAgent string           `form:"user-agent,omitempty"`
	AsRaw     bool             `form:"x-syft-raw" default:"false"` // If true, the request body will be read and sent as is
}

PollObjectRequest represents the request for polling

type PollResult

type PollResult struct {
	Status    int
	RequestID string
	Response  map[string]interface{}
}

PollResult represents the result of a poll operation

type PollStatus

type PollStatus string
const (
	PollStatusPending  PollStatus = "pending"
	PollStatusComplete PollStatus = "complete"
)

type RPCMsgStore

type RPCMsgStore interface {
	StoreMsg(ctx context.Context, path string, msgBytes []byte) error
	GetMsg(ctx context.Context, path string) (io.ReadCloser, error)
	DeleteMsg(ctx context.Context, path string) error
}

Message store interface for storing and retrieving messages

func NewBlobMsgStore

func NewBlobMsgStore(blob *blob.BlobService) RPCMsgStore

type SendHandler

type SendHandler struct {
	// contains filtered or unexported fields
}

SendHandler handles HTTP requests for sending messages

func New

func New(msgDispatcher MessageDispatcher, msgStore RPCMsgStore) *SendHandler

New creates a new send handler

func (*SendHandler) PollForResponse

func (h *SendHandler) PollForResponse(ctx *gin.Context)

PollForResponse handles polling for a response

func (*SendHandler) SendMsg

func (h *SendHandler) SendMsg(ctx *gin.Context)

SendMsg handles sending a message

type SendResult

type SendResult struct {
	Status    int
	RequestID string
	PollURL   string
	Response  map[string]interface{}
}

SendResult represents the result of a send operation

type SendService

type SendService struct {
	// contains filtered or unexported fields
}

SendService handles the business logic for message sending and polling

func NewSendService

func NewSendService(dispatch MessageDispatcher, store RPCMsgStore, cfg *Config) *SendService

NewSendService creates a new send service

func (*SendService) GetConfig

func (s *SendService) GetConfig() *Config

GetConfig returns the service configuration

func (*SendService) PollForResponse

func (s *SendService) PollForResponse(ctx context.Context, req *PollObjectRequest) (*PollResult, error)

PollForResponse handles polling for a response

func (*SendService) SendMessage

func (s *SendService) SendMessage(ctx context.Context, req *MessageRequest, bodyBytes []byte) (*SendResult, error)

SendMessage handles sending a message to a user

type SendServiceInterface

type SendServiceInterface interface {
	SendMessage(ctx context.Context, req *MessageRequest, bodyBytes []byte) (*SendResult, error)
	PollForResponse(ctx context.Context, req *PollObjectRequest) (*PollResult, error)

	GetConfig() *Config
	// contains filtered or unexported methods
}

SendServiceInterface defines the interface for the send service

type WSMsgDispatcher

type WSMsgDispatcher struct {
	// contains filtered or unexported fields
}

func (*WSMsgDispatcher) Dispatch

func (m *WSMsgDispatcher) Dispatch(datasite string, msg *syftmsg.Message) bool

Jump to

Keyboard shortcuts

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