config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const LocalFileFormatCsv = "csv"
View Source
const MmolConversionFactor = 0.0555

Variables

This section is empty.

Functions

func GetDir

func GetDir() (string, error)

func InitLog

func InitLog(w io.Writer, level slog.Level, format LogFormat)

func LogFormatStrings

func LogFormatStrings() []string

LogFormatStrings returns a slice of all String values of the enum

func UnitStrings

func UnitStrings() []string

UnitStrings returns a slice of all String values of the enum

Types

type Advanced

type Advanced struct {
	FetchDelay       Duration `` /* 188-byte string literal not displayed */
	FallbackInterval Duration `` /* 219-byte string literal not displayed */
	RoundAge         bool     `` /* 174-byte string literal not displayed */
}

type Arrows

type Arrows struct {
	DoubleUp      string `toml:"double-up"`
	SingleUp      string `toml:"single-up"`
	FortyFiveUp   string `toml:"forty-five-up"`
	Flat          string `toml:"flat"`
	FortyFiveDown string `toml:"forty-five-down"`
	SingleDown    string `toml:"single-down"`
	DoubleDown    string `toml:"double-down"`
	Unknown       string `toml:"unknown"`
}

type Config

type Config struct {
	File    string         `toml:"-"`
	Flags   *pflag.FlagSet `toml:"-"`
	Version string         `toml:"-"`

	Title       string      `toml:"title" comment:"Tray title."`
	URL         string      `toml:"url" comment:"Nightscout URL. (required)"`
	Token       string      `toml:"token" comment:"Nightscout token. Using an access token is recommended instead of the API secret."`
	Units       Unit        `toml:"units" comment:"Blood sugar unit. (one of: mg/dL, mmol/L)"`
	DynamicIcon DynamicIcon `toml:"dynamic-icon" comment:"Makes the tray icon show the current blood sugar reading."`
	Arrows      Arrows      `toml:"arrows" comment:"Customize the arrows."`
	LocalFile   LocalFile   `toml:"local-file" comment:"Enables writing the latest blood sugar to a local temporary file."`
	Log         Log         `toml:"log" comment:"Log configuration"`
	Advanced    Advanced    `toml:"advanced" comment:"Advanced settings."`
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Config

func (*Config) AddCallback

func (conf *Config) AddCallback(fn func()) int

func (*Config) InitLog

func (conf *Config) InitLog(w io.Writer)

func (*Config) Load

func (conf *Config) Load() error

func (*Config) RegisterFlags

func (conf *Config) RegisterFlags()

func (*Config) RemoveCallback

func (conf *Config) RemoveCallback(idx int)

func (*Config) Watch

func (conf *Config) Watch(ctx context.Context) error

func (*Config) Write

func (conf *Config) Write() error

type Duration

type Duration struct {
	time.Duration
}

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

type DynamicIcon

type DynamicIcon struct {
	Enabled     bool       `toml:"enabled"`
	FontColor   colorx.Hex `toml:"font-color" comment:"Hex code used to render text."`
	FontFile    string     `toml:"font-file" comment:"Font path or filename of a system font. If left blank, an embedded font will be used."`
	MaxFontSize float64    `toml:"max-font-size" comment:"Maximum font size in points."`
}

type LocalFile

type LocalFile struct {
	Enabled bool   `toml:"enabled"`
	Format  string `toml:"format" comment:"Local file format. (one of: csv)"`
	Path    string `toml:"path" comment:"Local file path. $TMPDIR will be replaced with the current temp directory."`
}

type Log

type Log struct {
	Level  string `toml:"level" comment:"Values: trace, debug, info, warn, error, fatal, panic"`
	Format string `toml:"format" comment:"Values: auto, color, plain, json"`
}

type LogFormat

type LogFormat uint8
const (
	FormatAuto LogFormat = iota
	FormatColor
	FormatPlain
	FormatJSON
)

func LogFormatString

func LogFormatString(s string) (LogFormat, error)

LogFormatString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func LogFormatValues

func LogFormatValues() []LogFormat

LogFormatValues returns all values of the enum

func (LogFormat) IsALogFormat

func (i LogFormat) IsALogFormat() bool

IsALogFormat returns "true" if the value is listed in the enum definition. "false" otherwise

func (LogFormat) MarshalText

func (i LogFormat) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for LogFormat

func (LogFormat) String

func (i LogFormat) String() string

func (*LogFormat) UnmarshalText

func (i *LogFormat) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for LogFormat

type Option

type Option func(conf *Config)

func WithVersion

func WithVersion(version string) Option

type TOMLParser

type TOMLParser struct{}

func (TOMLParser) Marshal

func (p TOMLParser) Marshal(o map[string]any) ([]byte, error)

func (TOMLParser) Unmarshal

func (p TOMLParser) Unmarshal(b []byte) (map[string]any, error)

type Unit

type Unit uint8
const (
	UnitMgdl Unit = iota // mg/dL
	UnitMmol             // mmol/L
)

func UnitString

func UnitString(s string) (Unit, error)

UnitString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func UnitValues

func UnitValues() []Unit

UnitValues returns all values of the enum

func (Unit) IsAUnit

func (i Unit) IsAUnit() bool

IsAUnit returns "true" if the value is listed in the enum definition. "false" otherwise

func (Unit) MarshalText

func (i Unit) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for Unit

func (Unit) String

func (i Unit) String() string

func (*Unit) UnmarshalText

func (i *Unit) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for Unit

Jump to

Keyboard shortcuts

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