Documentation ¶
Index ¶
- Constants
- func AppendFile(filePath string, str string) error
- func EpochWeek(dt time.Time) int
- func EqualsIgnoreTrailingNewlines(s1 string, s2 string) bool
- func Exists(path string) bool
- func FetchJSONAsModel(client *http.Client, url string, user string, password string, ...) error
- func GetLowerBound(t1 *time.Time, t2 *time.Time) time.Time
- func GetUpperBound(t1 *time.Time, t2 *time.Time) time.Time
- func Keys(m map[string]bool) []string
- func ParseISODate(s string) (time.Time, error)
- func ReadFile(filePath string) (string, error)
- func RemoveExtension(s string) string
- func SaveConfig(cfg *Config, cfgFile string) error
- func SaveConfigString(cfg *Config) (string, error)
- func SetTime(dt time.Time, tm time.Time) time.Time
- func SetToEndOfDay(dt time.Time) time.Time
- func SetToEndOfWeek(dt time.Time) time.Time
- func SetToStartOfDay(dt time.Time) time.Time
- func SetToStartOfWeek(dt time.Time) time.Time
- func SetWeekday(dt time.Time, wd time.Weekday) time.Time
- func WriteFile(filePath string, str string) error
- type Config
- func (cfg Config) GetBool(key string, defaultVal bool) bool
- func (cfg Config) GetByPath(path ConfigPath, defaultVal interface{}) interface{}
- func (cfg Config) GetInt(key string, defaultVal int) int
- func (cfg Config) GetIntOrFail(key string) int
- func (cfg Config) GetString(key string, defaultVal string) string
- func (cfg Config) GetStringList(key string, defaultVal []string) []string
- func (cfg Config) GetStringOrFail(key string) string
- func (cfg Config) GetSubConfig(key string) *Config
- func (cfg Config) HasKey(key string) bool
- func (cfg Config) SetByPath(path ConfigPath, val interface{}) bool
- func (cfg Config) SetString(key string, val string)
- type ConfigPath
- type FileConfig
Constants ¶
const Days = time.Hour * 24
Days is the duration of a day.
Variables ¶
This section is empty.
Functions ¶
func AppendFile ¶
AppendFile writes the passed string content at the end of the textfile.
func EpochWeek ¶
EpochWeek returns the number of weeks passed since January 1, 1970 UTC. Note this does not mean it's aligned for weekdays, i.e. the Monday after Sunday does not necessary have a higher EpochWeek number.
func EqualsIgnoreTrailingNewlines ¶ added in v1.3.0
EqualsIgnoreTrailingNewlines checks if s1 equals s2, but without taking trailing newlines into account.
func FetchJSONAsModel ¶
func FetchJSONAsModel(client *http.Client, url string, user string, password string, target interface{}) error
FetchJSONAsModel sends a GET request to the url and maps the JSON response to the target model.
func GetLowerBound ¶
GetLowerBound returns the earlier of two times. A nil time is considered infinitely late so won't be used if the other time is not nil.
func GetUpperBound ¶
GetUpperBound returns the later of two times. A nil time is considered infinitely early so won't be used if the other time is not nil.
func ParseISODate ¶
ParseISODate parses a string of format 2006-01-02.
func RemoveExtension ¶
RemoveExtension returns the filename without extension E.g. todo.txt -> todo
func SaveConfig ¶
SaveConfig saves the config object to a YAML file.
func SaveConfigString ¶
SaveConfigString saves the config object to a YAML string.
func SetToEndOfDay ¶
SetToEndOfDay changes the given datetime to the end of the day (23:59).
func SetToEndOfWeek ¶
SetToEndOfWeek changes the given datetime to the end of the week (Sunday).
func SetToStartOfDay ¶
SetToStartOfDay changes the given datetime to the start of the day (0:00).
func SetToStartOfWeek ¶
SetToStartOfWeek changes the given datetime to the start of the week (Monday).
func SetWeekday ¶
SetWeekday changes the given datetime to occur on the given week day.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds configuration values and has convenience methods to access these.
func LoadConfig ¶
LoadConfig loads a Config object from a YAML file.
func LoadConfigString ¶
LoadConfigString loads a Config object from a YAML string.
func (Config) GetBool ¶
GetBool returns the bool value for key, or defaultVal if the key is not found.
func (Config) GetByPath ¶
func (cfg Config) GetByPath(path ConfigPath, defaultVal interface{}) interface{}
GetByPath returns the value for the config path, or defaultVal if the key is not found.
func (Config) GetIntOrFail ¶
GetIntOrFail returns the int value for key, or exits the program with error code 1 if it doesn't exist.
func (Config) GetString ¶
GetString returns the string value for key, or defaultVal if the key is not found.
func (Config) GetStringList ¶
GetStringList returns the value for key, or defaultVal if the key is not found.
func (Config) GetStringOrFail ¶
GetStringOrFail returns the string value for key, or exits the program with error code 1 if it doesn't exist.
func (Config) GetSubConfig ¶
GetSubConfig returns the part of the config under key as a new Config object. If the key is not found an empty config is returned.
func (Config) SetByPath ¶
func (cfg Config) SetByPath(path ConfigPath, val interface{}) bool
SetByPath sets the value for the config path, if the path points to a correct sub-config. If the sub-config is not found, nothing is written - it does not create intermediate sub-configs. If the sub-config is found but doesn't have the final part of the path as a key yet, that key is created.
type ConfigPath ¶
type ConfigPath struct {
Parts []string
}
ConfigPath defines a path to a specific config value, where each part is a key in the next sub-config.
func (*ConfigPath) FromString ¶
func (p *ConfigPath) FromString(str string)
FromString sets the config path to the path denoted by the dot-separated string.
func (*ConfigPath) ToString ¶
func (p *ConfigPath) ToString() string
ToString converts the config path to a dot-separated string
type FileConfig ¶ added in v1.3.0
FileConfig stores the where the most important files for sibylgo are located.
func NewFileConfigFromConfig ¶ added in v1.3.0
func NewFileConfigFromConfig(cfg *Config) *FileConfig
NewFileConfigFromConfig reads the important file paths from the configuration and returns them as a FileConfig object.
func NewFileConfigFromTodoFile ¶ added in v1.3.0
func NewFileConfigFromTodoFile(todoFile string) *FileConfig
NewFileConfigFromTodoFile derives all the important file paths from the todoFile. It assumes that all other files are in the same directory as the todoFile.