config

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPort           = 53317
	DefaultMulticastGroup = "224.0.0.167"
	ProtocolVersion       = "2.1"
	DefaultSecurityDir    = ".localgo_security"
	DefaultSecurityFile   = "context.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Alias               string                        `json:"alias"`
	Port                int                           `json:"port"`
	HttpsEnabled        bool                          `json:"https_enabled"`
	MulticastGroup      string                        `json:"multicast_group"`
	DeviceModel         *string                       `json:"deviceModel"`
	DeviceType          model.DeviceType              `json:"deviceType"`
	SecurityContext     *crypto.StoredSecurityContext `json:"-"`
	SecurityPath        string                        `json:"-"`
	PIN                 string                        `json:"-"`
	DownloadDir         string                        `json:"-"`
	AutoAccept          bool                          `json:"-"`
	RandomFingerprint   string                        `json:"-"`
	MaxBodySize         int64                         `json:"-"`
	NoClipboard         bool                          `json:"-"` // skip clipboard; save text as a file instead
	HistoryFile         string                        `json:"-"` // path to transfer history jsonl file
	Quiet               bool                          `json:"-"` // quiet mode - minimal output
	ExecHook            string                        `json:"-"` // shell command to run after receiving file
	OpenDir             bool                          `json:"-"` // open download directory after transfer
	Concurrency         int                           `json:"-"` // max parallel uploads (0 = use default)
	MulticastInterface  string                        `json:"-"` // multicast network interface name
	Private             bool                          `json:"-"` // anonymize device identities
	DiscoveryStrategy   string                        `json:"-"` // discovery strategy: "full" (default) or "fast" (skip subnet scan)
	FileConflictResolve string                        `json:"-"` // conflict resolution: "rename" (default), "overwrite", "skip"
	BindAddress         string                        `json:"-"` // bind to specific interface/IP for listening
	ShareOnce           bool                          `json:"-"` // stop after first download (--once)
	StaticPeers         []string                      `json:"-"` // statically defined peer addresses for Tier 1 cache probe
	TrustedFingerprints []string                      `json:"-"` // fingerprints that bypass the transfer acceptance prompt

	Shell             string `json:"-"` // shell command prefix for exec hooks (default: "sh -c" or "cmd /c")
	ClipboardWriteCmd string `json:"-"` // custom clipboard write command
	ClipboardReadCmd  string `json:"-"` // custom clipboard read command
	CustomTLSCertPath string `json:"-"` // path to custom TLS certificate file
	CustomTLSKeyPath  string `json:"-"` // path to custom TLS private key file
	NotificationCmd   string `json:"-"` // custom notification command
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(src *Source, logger *logging.Logger) (*Config, error)

func (*Config) GetFingerprint added in v0.4.0

func (c *Config) GetFingerprint() string

GetFingerprint returns the appropriate fingerprint (certificate hash if HTTPS, random otherwise).

func (*Config) Protocol added in v0.4.0

func (c *Config) Protocol() model.ProtocolType

Protocol returns the protocol type based on HttpsEnabled.

func (*Config) SetCustomFingerprint added in v0.6.4

func (c *Config) SetCustomFingerprint(fp string)

SetCustomFingerprint overrides the advertised fingerprint with one computed from a user-supplied TLS certificate.

func (*Config) ToInfoDto

func (c *Config) ToInfoDto() model.InfoDto

ToInfoDto converts Config to model.InfoDto for discovery requests

func (*Config) ToMulticastDto added in v0.4.0

func (c *Config) ToMulticastDto(download bool) model.MulticastDto

ToMulticastDto creates a MulticastDto from the current configuration.

func (*Config) ToRegisterDto

func (c *Config) ToRegisterDto() model.RegisterDto

ToRegisterDto converts Config to model.RegisterDto for discovery requests

type Source added in v0.6.6

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

Source is a lightweight replacement for viper. It resolves config values with the precedence: programmatic overrides > environment > file > defaults.

Environment variables are named LOCALSEND_<KEY> with '-' replaced by '_'.

func LoadSource added in v0.6.6

func LoadSource() *Source

LoadSource searches the standard config directories for a config file and returns a Source bound to it. Returns an empty Source if no file is found.

func LoadSourceFile added in v0.6.6

func LoadSourceFile(path string) (*Source, error)

LoadSourceFile returns a Source bound to an explicitly selected config file.

func NewSourceFromMap added in v0.6.6

func NewSourceFromMap(m map[string]any) *Source

NewSourceFromMap returns a Source initialised with the given programmatic overrides (used for tests and callers that supply values directly).

func (*Source) FilePath added in v0.6.6

func (s *Source) FilePath() string

FilePath returns the resolved config file path, or the default location when no file has been found or selected.

func (*Source) Get added in v0.6.6

func (s *Source) Get(key string) any

Get returns the resolved value as-is.

func (*Source) GetInt added in v0.6.6

func (s *Source) GetInt(key string) int

GetInt returns the int form of the resolved value.

func (*Source) GetString added in v0.6.6

func (s *Source) GetString(key string) string

GetString returns the string form of the resolved value.

func (*Source) GetStringSlice added in v0.6.6

func (s *Source) GetStringSlice(key string) []string

GetStringSlice returns the resolved value as a list of strings. A comma-separated environment variable or a YAML scalar yields a single item.

func (*Source) InFile added in v0.6.6

func (s *Source) InFile(key string) bool

InFile reports whether the key is present in the config file.

func (*Source) IsSet added in v0.6.6

func (s *Source) IsSet(key string) bool

IsSet reports whether the key has a value from any source.

func (*Source) Save added in v0.6.6

func (s *Source) Save() error

Save writes the file entries merged with programmatic overrides to the resolved config path, creating parent directories as needed.

func (*Source) Set added in v0.6.6

func (s *Source) Set(key string, val any)

Set stores a programmatic override for the key.

func (*Source) SetConfigFile added in v0.6.6

func (s *Source) SetConfigFile(path string)

SetConfigFile overrides the config file path used by FilePath and Save.

func (*Source) SetDefault added in v0.6.6

func (s *Source) SetDefault(key string, val any)

SetDefault registers a fallback value used when no other source has the key.

func (*Source) Unset added in v0.6.6

func (s *Source) Unset(key string)

Unset removes the key from the file and overrides.

Jump to

Keyboard shortcuts

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