config

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0, BSD-2-Clause-Views, BSD-3-Clause, + 4 more Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfigDir is the path to the directory storing the application configuration.
	ConfigDir string
	// DataDir is the path to the directory storing the application data.
	DataDir string
	// Version is the current version of the application. Set at compile time for production builds using ldflags (see tasks in the /tasks/build directory).
	Version = "development"
)
View Source
var KeyStorageEnum = []struct {
	Value  KeyStorageType
	TSName string
}{
	{KeyStorageDisk, "DISK"},
	{KeyStorageHardware, "HARDWARE"},
}
View Source
var RoutingModeEnum = []struct {
	Value  RoutingMode
	TSName string
}{
	{RoutingModeBlocklist, "BLOCKLIST"},
	{RoutingModeAllowlist, "ALLOWLIST"},
}
View Source
var UpdatePolicyEnum = []struct {
	Value  UpdatePolicyType
	TSName string
}{
	{UpdatePolicyAutomatic, "AUTOMATIC"},
	{UpdatePolicyPrompt, "PROMPT"},
	{UpdatePolicyDisabled, "DISABLED"},
}

Functions

func GetCacheDir

func GetCacheDir() (string, error)

Types

type Config

type Config struct {
	Filter struct {
		FilterLists []FilterList `json:"filterLists"`
		// Deprecated: use Rules.
		MyRules []string `json:"myRules"`
		Rules   []string `json:"rules"`
		// Deprecated: assets are served by the proxy itself, under constants.LocalEndpointHost.
		// omitempty keeps the dead key out of fresh configs; configs stamped by the
		// v0.17.0 migration carry a non-zero value and keep serialising it.
		AssetPort int `json:"assetPort,omitempty"`
	} `json:"filter"`
	Certmanager struct {
		CAInstalled bool `json:"caInstalled"`
		// KeyStorage describes the installed CA, not a pending choice. It only changes after the
		// old CA has been uninstalled, so it always matches the CA that CAInstalled refers to.
		KeyStorage KeyStorageType `json:"keyStorage"`
	} `json:"certmanager"`
	Proxy struct {
		Port         int           `json:"port"`
		IgnoredHosts []string      `json:"ignoredHosts"`
		PACPort      int           `json:"pacPort"`
		Routing      RoutingConfig `json:"routing"`
	} `json:"proxy"`
	UpdatePolicy UpdatePolicyType `json:"updatePolicy"`

	Locale string `json:"locale"`
	// contains filtered or unexported fields
}

Config stores and manages the configuration for the application. Although all fields are public, this is only for use by the JSON marshaller. All access to the Config should be done through the exported methods.

func New

func New() (*Config, error)

func (*Config) AddFilterList

func (c *Config) AddFilterList(list FilterList) error

AddFilterList adds a new filter list to the list of enabled filter lists.

func (*Config) AddFilterLists

func (c *Config) AddFilterLists(lists []FilterList) error

func (*Config) ExportDebugData

func (c *Config) ExportDebugData() (string, error)

func (*Config) GetCAInstalled

func (c *Config) GetCAInstalled() bool

GetCAInstalled returns whether the CA is installed.

func (*Config) GetFilterLists

func (c *Config) GetFilterLists() []FilterList

GetFilterLists returns the list of enabled filter lists.

func (*Config) GetFilterListsByLocales

func (c *Config) GetFilterListsByLocales(searchLocales []string) []FilterList

func (*Config) GetFirstLaunch

func (c *Config) GetFirstLaunch() bool

func (*Config) GetIgnoredHosts

func (c *Config) GetIgnoredHosts() []string

GetIgnoredHosts returns the list of ignored hosts.

func (*Config) GetKeyStorage added in v0.26.0

func (c *Config) GetKeyStorage() KeyStorageType

GetKeyStorage returns where the installed CA's private key is stored.

func (*Config) GetLocale

func (c *Config) GetLocale() string

func (*Config) GetPACPort

func (c *Config) GetPACPort() int

func (*Config) GetPort

func (c *Config) GetPort() int

GetPort returns the port the proxy is set to listen on.

func (*Config) GetRouting

func (c *Config) GetRouting() RoutingConfig

func (*Config) GetRules

func (c *Config) GetRules() []string

func (*Config) GetTargetTypeFilterLists

func (c *Config) GetTargetTypeFilterLists(targetType FilterListType) []FilterList

GetTargetTypeFilterLists returns the list of filter lists with particular type.

func (*Config) GetUpdatePolicy

func (c *Config) GetUpdatePolicy() UpdatePolicyType

func (*Config) GetVersion

func (c *Config) GetVersion() string

func (*Config) RemoveFilterList

func (c *Config) RemoveFilterList(url string) error

RemoveFilterList removes a filter list from the list of enabled filter lists.

func (*Config) RunMigrations

func (c *Config) RunMigrations()

RunMigrations brings the config, and any other state migrations touch, up to date with this build.

func (*Config) SetCAInstalled

func (c *Config) SetCAInstalled(caInstalled bool)

SetCAInstalled sets whether the CA is installed.

func (*Config) SetIgnoredHosts

func (c *Config) SetIgnoredHosts(hosts []string) error

SetIgnoredHosts sets the list of ignored hosts.

func (*Config) SetKeyStorage added in v0.26.0

func (c *Config) SetKeyStorage(storage KeyStorageType) error

SetKeyStorage records where the CA's private key is stored. It must only be called while no CA is installed, which App.SetCAKeyStorage ensures.

func (*Config) SetLocale

func (c *Config) SetLocale(l string) error

func (*Config) SetPACPort added in v0.23.0

func (c *Config) SetPACPort(port int) error

SetPACPort sets the port the PAC server is set to listen on.

func (*Config) SetPort

func (c *Config) SetPort(port int) error

SetPort sets the port the proxy is set to listen on.

func (*Config) SetRouting

func (c *Config) SetRouting(routing RoutingConfig) error

func (*Config) SetRules

func (c *Config) SetRules(rules []string) error

func (*Config) SetUpdatePolicy

func (c *Config) SetUpdatePolicy(p UpdatePolicyType) error

func (*Config) ToggleFilterList

func (c *Config) ToggleFilterList(url string, enabled bool) error

ToggleFilterList toggles the enabled state of a filter list.

type DebugData

type DebugData struct {
	EnabledFilterListURLs []string       `json:"enabledFilterListURLs"`
	Rules                 []string       `json:"rules"`
	Platform              string         `json:"platform"`
	Architecture          string         `json:"architecture"`
	Version               string         `json:"version"`
	KeyStorage            KeyStorageType `json:"keyStorage"`
}

type FilterList

type FilterList struct {
	Name    string         `json:"name"`
	Type    FilterListType `json:"type"`
	URL     string         `json:"url"`
	Enabled bool           `json:"enabled"`
	Trusted bool           `json:"trusted"`
	Locales []string       `json:"locales"`
}

type FilterListType

type FilterListType string
const (
	FilterListTypeGeneral          FilterListType = "general"
	FilterListTypeAds              FilterListType = "ads"
	FilterListTypePrivacy          FilterListType = "privacy"
	FilterListTypeMalware          FilterListType = "malware"
	FilterListTypeRegional         FilterListType = "regional"
	FilterListTypeDigitalWellbeing FilterListType = "digitalWellbeing"
	FilterListTypeCustom           FilterListType = "custom"
)

type KeyStorageType added in v0.26.0

type KeyStorageType string

KeyStorageType says where the root CA's private key is stored.

const (
	// KeyStorageDisk keeps the key in a PEM file in the data directory.
	KeyStorageDisk KeyStorageType = "disk"
	// KeyStorageHardware keeps the key in the Secure Enclave (macOS) or the TPM (Windows).
	KeyStorageHardware KeyStorageType = "hardware"
)

type RoutingConfig

type RoutingConfig struct {
	Mode     RoutingMode `json:"mode"`
	AppPaths []string    `json:"appPaths"`
}

type RoutingMode

type RoutingMode string
const (
	RoutingModeBlocklist RoutingMode = "blocklist"
	RoutingModeAllowlist RoutingMode = "allowlist"
)

type UpdatePolicyType

type UpdatePolicyType string
const (
	UpdatePolicyAutomatic UpdatePolicyType = "automatic"
	UpdatePolicyPrompt    UpdatePolicyType = "prompt"
	UpdatePolicyDisabled  UpdatePolicyType = "disabled"
)

Jump to

Keyboard shortcuts

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