config

package
v0.0.0-...-e2578a2 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Video VideoSection `toml:"video"`
	Lirc  LircSection  `toml:"lirc"`
}

File represents the fields and sections in the configuration file.

func (*File) Get

func (config *File) Get(fields string) (interface{}, error)

Get retrieves a section or a value from a key in a section.

fields is either only the section name e.g. lirc or a value from the section e.g. lirc.remote

Returns a generic interface that you can use type assertions to work with the type it actually is e.g. to the return value containing the interface from the call Get("lirc") you could use .(LircSection).SocketPath to retrieve the socket path value from that section.

func (*File) GetConfigDirPath

func (config *File) GetConfigDirPath() (string, error)

GetConfigDirPath retrieves the absolute path to the configuration directory in an OS independent way.

Returns: (absolute path to the configuration direction, any error) If an error occurs, an empty string is returned as the path.

func (*File) GetConfigFilePath

func (config *File) GetConfigFilePath() (string, error)

GetConfigFilePath retrieves the absolute path to the configuration file in an OS independent way.

Lookup hierarchy:

  1. HC_CONFIG_PATH environment variable. This will only be used if the path set in the environment variable is file that exists.
  2. ~/.stb/config.toml will be looked for next. This is the configuration path to the user-defined configuration.
  3. Internal config file in the package will be used. This is the configuration file that is used by default if the above two do not exist.

Returns: (the absolute path to configuration file, any error) If an error occurs, an empty string is returned as the path.

func (*File) Parse

func (config *File) Parse() error

Parse parses the config file and reads the fields into this File. After it is parsed, you can then directly access the fields.

Example:

config.Parse()
config.video.device = "/dev/device0"
config.Save()

func (*File) Save

func (config *File) Save() error

Save saves the current state of this file.

func (*File) SetupUserConfig

func (config *File) SetupUserConfig() (bool, bool, error)

SetupUserConfig initializes the user's configuration file setup by creating the configuration folder at ~/.stb/ and configuration file at ~/.stb/config.toml. It only creates these if they do not exist already.

Returns: (if folder is created, if file is created, any error)

func (*File) Stringify

func (config *File) Stringify() (string, error)

Stringify retrieves the configuration file in a string format.

type LircSection

type LircSection struct {
	SocketPath string `toml:"socketPath"`
	Remote     string `toml:"remote"`
}

LircSection holds the values for the lirc section in the configuration file.

type VideoSection

type VideoSection struct {
	DeviceId int `toml:"deviceId"`
}

VideoSection holds the values for the video section in the configuration file.

Jump to

Keyboard shortcuts

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