syncthing

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncSecretName = "nocalhost-syncthing-secret"

	RemoteHome = "/var/syncthing/config"
	Bind       = "127.0.0.1"
	Nocalhost  = "nocalhost"

	LogFile     = "syncthing.log"
	IgnoredFIle = ".nhignore"

	// Use to access syncthing API
	DefaultAPIKey = "nocalhost"

	// DefaultRemoteDeviceID remote syncthing ID
	DefaultRemoteDeviceID = "MDPJNTF-OSPJC65-LZNCQGD-3AWRUW6-BYJULSS-GOCA2TU-5DWWBNC-TKM4VQ5"

	// DefaultFileWatcherDelay how much to wait before starting a sync after a file change
	DefaultFileWatcherDelay = 5

	// may result bug due to syncthing config changing
	DefaultFolderName = "nh-1"

	// ClusterPort is the port used by syncthing in the cluster
	ClusterPort = 22000

	// GUIPort is the port used by syncthing in the cluster for the http endpoint
	GUIPort = 8384

	EnableParseFromGitIgnore  = "#enableParseFromGitIgnore"
	DisableParseFromGitIgnore = "#disableParseFromGitIgnore"
)

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(from, to string) error

func FileExists

func FileExists(name string) bool

func GetBinaryName

func GetBinaryName() string

func GetDir

func GetDir(path string) string

func GetDownloadURL

func GetDownloadURL(os, arch, version string) (string, error)

func IsSubPathFolder

func IsSubPathFolder(path string, paths []string) (bool, error)

IsSubPathFolder checks if a sync folder is a subpath of another sync folder

func NewAPIClient

func NewAPIClient() *http.Client

NewAPIClient returns a new syncthing api client configured to call the syncthing api

func Stop

func Stop(pid int, force bool) error

Stop syncthing background process

Types

type Folder

type Folder struct {
	Name         string `yaml:"name"`
	LocalPath    string `yaml:"localPath"`
	RemotePath   string `yaml:"remotePath"`
	Retries      int    `yaml:"-"`
	SentStIgnore bool   `yaml:"-"`
}

Folder represents a sync folder

type Ignores

type Ignores struct {
	Ignore []string `json:"ignore"`
}

Ignores represents the .stignore file

type Syncthing

type Syncthing struct {
	APIKey          string       `yaml:"apikey"`
	GUIPassword     string       `yaml:"password"`
	GUIPasswordHash string       `yaml:"-"`
	BinPath         string       `yaml:"-"`
	Client          *http.Client `yaml:"-"`

	Folders                  []*Folder `yaml:"folders"`
	FileWatcherDelay         int       `yaml:"-"`
	ForceSendOnly            bool      `yaml:"-"`
	GUIAddress               string    `yaml:"local"`
	LocalHome                string    `yaml:"-"`
	RemoteHome               string    `yaml:"-"`
	LogPath                  string    `yaml:"-"`
	ListenAddress            string    `yaml:"-"`
	RemoteAddress            string    `yaml:"-"`
	RemoteDeviceID           string    `yaml:"-"`
	RemoteGUIAddress         string    `yaml:"remote"`
	RemoteGUIPort            int       `yaml:"-"`
	RemotePort               int       `yaml:"-"`
	LocalGUIPort             int       `yaml:"-"`
	LocalPort                int       `yaml:"-"`
	Type                     string    `yaml:"-"`
	IgnoreDelete             bool      `yaml:"-"`
	PortForwardBackGroundPid int       `yaml:"-"`
	SyncthingBackGroundPid   int       `yaml:"-"`

	RescanInterval string `yaml:"-"`

	// resolve ignore/sync from pattern
	SyncedPattern  []string `yaml:"-"`
	IgnoredPattern []string `yaml:"-"`

	// resolve ignore/sync from gitignore
	EnableParseFromGitIgnore bool `yaml:"-"`
	// contains filtered or unexported fields
}

func (*Syncthing) APICall

func (s *Syncthing) APICall(
	ctx context.Context, url, method string, code int, params map[string]string, local bool,
	body []byte, readBody bool,
	maxRetries int,
) ([]byte, error)

APICall calls the syncthing API and returns the parsed json or an error

func (*Syncthing) GetLocalConfigXML

func (s *Syncthing) GetLocalConfigXML() ([]byte, error)

func (*Syncthing) GetRemoteConfigXML

func (s *Syncthing) GetRemoteConfigXML() ([]byte, error)

func (*Syncthing) Run

func (s *Syncthing) Run(ctx context.Context) error

Run local syncthing server

func (*Syncthing) UpdateConfig

func (s *Syncthing) UpdateConfig() error

UpdateConfig updates the syncthing config file

type SyncthingInstaller

type SyncthingInstaller struct {
	BinPath  string
	Version  string
	CommitId string
}

func NewInstaller

func NewInstaller(binPath string, version string, commitId string) *SyncthingInstaller

func (*SyncthingInstaller) InstallIfNeeded

func (s *SyncthingInstaller) InstallIfNeeded() (bool, error)

the return val bool is only for test case, it shows that whether download again

Directories

Path Synopsis
network
req

Jump to

Keyboard shortcuts

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