config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config = DefaultConfig

Config is the shared configuration instance.

View Source
var DefaultConfig = &Configuration{
	ProgramFolder:      filepath.Join(os.Getenv("HOME"), ".hget"),
	ConfigFilename:     "config.toml",
	TaskFilename:       "task.toml",
	DisplayProgressBar: isatty.IsTerminal(os.Stdout.Fd()),
	UseHashLength:      uint8(16),
	SaveWithHash:       false,
	CopyNBytes:         int64(250),
	LogLevel:           uint8(2),
	DownloadFolder:     "",
}

DefaultConfig is the default configuration instance. The Config instance is based on these defaults.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	// ProgramFolder is the folder in which the program will store his information
	// about the ongoing downloads. This path is relative to $HOME.
	ProgramFolder string `toml:"-"`

	// ConfigFilename is the filename of the configuration file.
	ConfigFilename string `toml:"-"`

	// TaskFilename represents the state of a download. This file will be located
	// in $HOME/ProgramFolder/Download
	TaskFilename string `toml:"-"`

	// DisplayProgressBar enables/disables the display of the progress bar.
	DisplayProgressBar bool `toml:"display_progress_bar"`

	// UseHashLength sets the length of the hash used to prevent collisions.
	// Note that this can never be more than 32
	UseHashLength uint8 `toml:"use_hash_length"`

	// SaveWithHash enables/disables the collision protection using a hash
	// while moving the file from inside the program to outside.
	SaveWithHash bool `toml:"save_with_hash"`

	// CopyNBytes sets the bytes to copy in a row from the response body.
	CopyNBytes int64 `toml:"copy_n_bytes"`

	// LogLevel restricts the logs to what the user wants to get.
	// 0 means no logs, 1 only important logs and 2 all logs.
	LogLevel uint8 `toml:"log_level"`

	// DownloadFolder defines in which directory the downloaded file will be moved to.
	// If it is empty, then the download folder will be the terminal cwd.
	DownloadFolder string `toml:"download_folder"`
}

Configuration is the shared object which is used to persist information both inside the program and outside of it.

func LoadConfig

func LoadConfig(configFilepath string) (*Configuration, error)

LoadConfig loads the configuration from a toml file merging it with the default config.

Jump to

Keyboard shortcuts

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