syncthing

package
v0.3.45 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET  = "GET"
	POST = "POST"
	PUT  = "PUT"
)
View Source
const (
	DefaultLocalPort           = "8386"
	DefaultRemotePort          = "8384"
	DefaultRemoteAPIAddress    = "127.0.0.1:8384"
	DefaultApiKey              = "envd"
	DefaultLocalDeviceAddress  = "tcp://127.0.0.1:22000"
	DefaultRemoteDeviceAddress = "tcp://127.0.0.1:22001"
)
View Source
const (
	XML  = "xml"
	JSON = "json"
)
View Source
const ConfigSaved = "ConfigSaved"

Variables

This section is empty.

Functions

func CleanLocalConfig

func CleanLocalConfig(name string) error

func ConnectDevices

func ConnectDevices(s1 *Syncthing, s2 *Syncthing) error

func GetConfigBytes

func GetConfigBytes(cfg *config.Configuration, outputType string) (configByte []byte, err error)

Get syncthing configuration in bytes with format XML or JSON

func GetConfigFilePath

func GetConfigFilePath(homeDirectory string) string

func GetHomeDirectory

func GetHomeDirectory() (string, error)

func GetSyncthingBinPath

func GetSyncthingBinPath() string

func InstallSyncthing

func InstallSyncthing() error

func IsInstalled

func IsInstalled() bool

func NewAPIClient

func NewAPIClient() *http.Client

func ParsePortFromAddress

func ParsePortFromAddress(addr string) string

func SyncFolder

func SyncFolder(s1 *Syncthing, s2 *Syncthing, dir1 string, dir2 string) error

Types

type Client

type Client struct {
	ApiKey   string
	Client   *http.Client
	BasePath string
}

func (*Client) SendRequest

func (c *Client) SendRequest(method string, url string, params map[string]string, body []byte) ([]byte, error)

Makes API calls to the syncthing instance's rest api

type ConfigSavedEvent

type ConfigSavedEvent struct {
	Type     string               `json:"type"`
	Id       int64                `json:"id"`
	GlobalId int64                `json:"globalID"`
	Time     string               `json:"time"`
	Data     config.Configuration `json:"data"`
}

type GeneralEvent

type GeneralEvent struct {
	Type     string      `json:"type"`
	Id       int64       `json:"id"`
	GlobalId int64       `json:"globalID"`
	Time     string      `json:"time"`
	Data     interface{} `json:"data"`
}

type Status

type Status struct {
	State      string `json:"state"`
	PullErrors int64  `json:"pullErrors"`
}

Status represents the status of a syncthing folder.

type Syncthing

type Syncthing struct {
	Name          string
	Cmd           *exec.Cmd
	Config        *config.Configuration
	PrevConfig    config.Configuration // Unapplied config
	HomeDirectory string
	Port          string
	DeviceID      protocol.DeviceID
	Client        *Client
	ApiKey        string

	DeviceAddress string
	// contains filtered or unexported fields
}

func InitializeLocalSyncthing

func InitializeLocalSyncthing(name string) (*Syncthing, error)

Initializes the local syncthing instance

func InitializeRemoteSyncthing

func InitializeRemoteSyncthing() (*Syncthing, error)

Initializes the remote syncthing instance

func (*Syncthing) ApplyConfig

func (s *Syncthing) ApplyConfig() error

Applies the config to the syncthing instance and waits for the config to be applied

func (*Syncthing) CleanupSyncthing

func (s *Syncthing) CleanupSyncthing() error

func (*Syncthing) GetConfig

func (s *Syncthing) GetConfig() (*config.Configuration, error)

Fetches the latest configuration from the syncthing rest api

func (*Syncthing) GetConfigSavedEvents

func (s *Syncthing) GetConfigSavedEvents() ([]*ConfigSavedEvent, error)

Fetches the latest config saved events using the syncthing rest api starting from the latest event id

func (*Syncthing) GetDeviceAddressPort

func (s *Syncthing) GetDeviceAddressPort() string

func (*Syncthing) GetMostRecentEvent

func (s *Syncthing) GetMostRecentEvent() (*GeneralEvent, error)

Fetches the most recent event using the syncthing rest api

func (*Syncthing) IsRunning

func (s *Syncthing) IsRunning() bool

func (*Syncthing) NewClient

func (s *Syncthing) NewClient() *Client

func (*Syncthing) Ping

func (s *Syncthing) Ping() (bool, error)

func (*Syncthing) PullLatestConfig

func (s *Syncthing) PullLatestConfig() error

Fetches the latest configuration from the syncthing rest api and applies it to the syncthing struct

func (*Syncthing) SetDeviceAddress

func (s *Syncthing) SetDeviceAddress(addr string) (err error)

This method can only be called when the devices are not connected

func (*Syncthing) StartLocalSyncthing

func (s *Syncthing) StartLocalSyncthing() error

func (*Syncthing) StopLocalSyncthing

func (s *Syncthing) StopLocalSyncthing()

func (*Syncthing) WaitForConfigApply

func (s *Syncthing) WaitForConfigApply(timeout time.Duration) error

func (*Syncthing) WaitForStartup

func (s *Syncthing) WaitForStartup(timeout time.Duration) error

func (*Syncthing) WriteLocalConfig

func (s *Syncthing) WriteLocalConfig() error

Jump to

Keyboard shortcuts

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