syncing

package
v0.0.0-...-4315c0a Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package syncing provides a way to sync apps between peers

Index

Constants

This section is empty.

Variables

View Source
var ErrPeerNotFound = errors.New("not found")

ErrPeerNotFound is returned when a peer is not found in the metadata storage

Functions

This section is empty.

Types

type AppSource

type AppSource interface {
	List() ([]apps.App, error)
}

AppSource is an interface for listing apps

func NewAddressEnrichingAppSource

func NewAddressEnrichingAppSource(hostname string, child AppSource) AppSource

NewAddressEnrichingAppSource creates a new AppSource that enriches the apps with the given hostname

func NewInMemoryAppStorage

func NewInMemoryAppStorage() AppSource

NewInMemoryAppStorage creates a new in-memory AppSource instance

func NewPeerEnrichingAppSource

func NewPeerEnrichingAppSource(peer string, child AppSource) AppSource

NewPeerEnrichingAppSource creates a new AppSource that enriches the apps with the given peer

type AppStateChangeGenerator

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

AppStateChangeGenerator is a generator that listens for changes in the app state and generates events

func NewAppStateChangeGenerator

func NewAppStateChangeGenerator() *AppStateChangeGenerator

NewAppStateChangeGenerator creates a new AppStateChangeGenerator

func (*AppStateChangeGenerator) Changes

Changes returns the channel where changes are sent

func (*AppStateChangeGenerator) UpdateForPeer

func (s *AppStateChangeGenerator) UpdateForPeer(peer string, theApps []apps.App)

UpdateForPeer is called when a sync message is received

type Client

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

Client is a struct that orchestrates all the operations that are performed client-side when executing app list synchronizations

func NewClient

func NewClient(
	myName string,
	nginxAdapter *AppStateChangeGenerator,
	encoder Encoder,
	interval time.Duration,
	apps AppSource,
	transport ClientTransport,
	MetadataFactory MetadataFactory,
) *Client

NewClient creates a new SyncingClient instance

func NewHTTPClient

func NewHTTPClient(
	myName string,
	nginxAdapter *AppStateChangeGenerator,
	encoder Encoder,
	interval time.Duration,
	apps AppSource,
	pr pairing.Response,
	metadata MetadataFactory,

) (*Client, error)

NewHTTPClient creates a new SyncingClient instance with HTTP transport

func (*Client) Start

func (c *Client) Start() error

Start starts the syncing client

type ClientTransport

type ClientTransport interface {
	Sync([]byte) ([]byte, error)
}

ClientTransport is an interface for syncing clients transport. Example implementations can be http, grpc, etc.

func NewHTTPClientTransport

func NewHTTPClientTransport(serverURL string, timeout time.Duration) ClientTransport

NewHTTPClientTransport creates a new SyncClientTransport instance

type Encoder

type Encoder interface {
	Encode(Message) ([]byte, error)
	Decode([]byte) (Message, error)
}

Encoder is an interface for encoding and decoding syncing messages

func NewJSONSyncingEncoder

func NewJSONSyncingEncoder() Encoder

NewJSONSyncingEncoder creates a new SyncingEncoder instance

type IncomingSyncRequest

type IncomingSyncRequest struct {
	Request  []byte
	Response chan []byte
	Err      chan error
}

IncomingSyncRequest is a struct that represents raw incoming sync requests

type Message

type Message struct {
	Peer     string
	Metadata Metadata
	Apps     []apps.App
}

Message is a message that contains a list of apps and the peer that sent them

type Metadata

type Metadata map[string]any

Metadata allows storing arbitrary metadata in sync messages

type MetadataFactory

type MetadataFactory interface {
	Get() (Metadata, error)
}

MetadataFactory is an interface for creating metadata, can be used for example for loading mounted secrets in kubernetes and reloading metadata without restarting the application

func NewStaticMetadataFactory

func NewStaticMetadataFactory(metadata Metadata) MetadataFactory

NewStaticMetadataFactory creates a new static metadata factory

type MetadataListItem

type MetadataListItem struct {
	Peer     string
	Metadata Metadata
}

MetadataListItem is used to present metadata in a list

type MetadataStorage

type MetadataStorage interface {
	List() ([]MetadataListItem, error)
	Set(peer string, metadata Metadata) error
	Get(peer string) (Metadata, error)
}

MetadataStorage is an interface for storing and retrieving metadata

func NewBoltMetadataStorage

func NewBoltMetadataStorage(path string) (MetadataStorage, error)

NewBoltMetadataStorage creates a new metadata storage that stores metadata in a BoltDB database

func NewCachingMetadataStorage

func NewCachingMetadataStorage(storage MetadataStorage) MetadataStorage

NewCachingMetadataStorage creates a new metadata storage that caches metadata in memory

func NewInMemoryMetadataStorage

func NewInMemoryMetadataStorage() MetadataStorage

NewInMemoryMetadataStorage creates a new in-memory metadata storage

type Server

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

Server orchestrates all the operations that are performed server-side when executing app list synchronizations

func NewServer

func NewServer(
	myName string,
	stateGenerator *AppStateChangeGenerator,
	apps AppSource,
	encoder Encoder,
	transport ServerTransport,
	peers pairing.PeerStorage,
	metadata MetadataStorage,
) *Server

NewServer creates a new SyncingServer instance

func (*Server) Start

func (s *Server) Start()

Start starts the syncing server

type ServerTransport

type ServerTransport interface {
	Syncs() <-chan IncomingSyncRequest
	Metadata() map[string]string
}

ServerTransport is an interface for syncing servers transport, similar to SyncClientTransport

func NewHTTPServerSyncingTransport

func NewHTTPServerSyncingTransport(server *http.Server) ServerTransport

NewHTTPServerSyncingTransport creates a new SyncServerTransport instance

Jump to

Keyboard shortcuts

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