util

package
Version: v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ApplicationFolder = "/usr/share/applications/"
View Source
const DateFormat = "2006-01-02"
View Source
const GermanLayout = "02-01-2006"

Variables

This section is empty.

Functions

func AbsolutePathWithWD

func AbsolutePathWithWD(path string) string

AbsolutePathWithWD returns the absolute path of a given path in relation to the current working dir. This is mainly used to normalize user inputs (like for assets).

func ApplyTemplate

func ApplyTemplate(name, tpl string, data interface{}) string

func AskBool

func AskBool(name, desc string, defaultValue bool) bool

func AskDate

func AskDate(name, desc string, defaultValue time.Time) string

func AskFloat

func AskFloat(name, desc string, defaultValue float64) float64

func AskForConformation

func AskForConformation(question string) bool

func AskInt

func AskInt(name, desc string, defaultValue int) int

func AskIntFromList

func AskIntFromList(name, desc string, searchItems SearchItems) int

func AskIntFromListSearch

func AskIntFromListSearch(name, desc string, searchItems SearchItems) int

func AskString

func AskString(name, desc, defaultValue string) string

func AskStringFromListSearch

func AskStringFromListSearch(name, desc string, searchItems SearchItems) string

func AskStringFromSearch

func AskStringFromSearch(name, desc string, searchItems SearchItems) string

func AskStringFromSearchWithNew

func AskStringFromSearchWithNew(name, desc string, searchItems SearchItems, newFunction func(arg interface{}) interface{}, arg interface{}) (value string, newElement interface{})

func CompareFloats

func CompareFloats(a float64, b float64) bool

CompareFloats rounds both numbers to their third decimal place and compares them.

func Contains

func Contains(list []string, key string) bool

func DateRangeFromYear

func DateRangeFromYear(year int) (from, to time.Time)

func EscapedSplit

func EscapedSplit(input, sep string) []string

EscapedSplit separates a string with a given separator while ignoring separators which are escaped with a backslash (ex.: "\:" is ignored when splitting by ":" ).

func FileExist

func FileExist(path string) bool

FileExist returns whether a file at a given path exists or not.

func OpenYaml

func OpenYaml(data interface{}, path, dataType string)

OpenYaml opens a file and tries to marshal its content to the given interface. The elementType parameter is used in error messages.

func RelativeAssetPath

func RelativeAssetPath(absolute, asset string) string

func SaveToYaml

func SaveToYaml(data interface{}, path, dataType string)

SaveToYaml writes the element (utils) as a json file to the given path. The elementType parameter is used in error messages.

func TerminalWidth

func TerminalWidth() (int, error)

func ValidDate

func ValidDate(format, date string) bool

Types

type Checkable

type Checkable interface {
	Validate() ValidateResults
}

type Conditions

type Conditions []struct {
	Condition bool
	Message   string
	Level     FlawLevel
}

type External

type External struct {
	Running bool
	// contains filtered or unexported fields
}

func NewExternal

func NewExternal(path string, retainFocus bool) External

func (External) Close

func (e External) Close()

func (*External) Open

func (e *External) Open()

type FlawLevel

type FlawLevel int

FlawLevel states the importance of a validation error. The levels also states in which step the validation should be fixed.

const (
	// UndefinedFlaw was not defined by the programmer.
	UndefinedFlaw FlawLevel = iota
	// FundamentalFlaw has to be fixed right now.
	FundamentalFlaw
	// BeforeImportFlaw should be fixed before import into Acc.
	BeforeImportFlaw
	// BeforeMergeFlaw should be fixed before using any merging functions.
	BeforeMergeFlaw
	// BeforeExportFlaw should be fixed before using export functions.
	BeforeExportFlaw
)

func (FlawLevel) String

func (l FlawLevel) String() string

String returns a human readable representation for the flaw level.

type Money

type Money struct {
	*money.Money
}

func AskMoney

func AskMoney(name, desc string, defaultValue Money, currency string) Money

func NewMoney

func NewMoney(amount int64, code string) Money

func NewMoneyFromFloat

func NewMoneyFromFloat(value float64, currency string) Money

NewMoneyFromFloat returns a new Money object from the given string. As floating point numbers are not a good idea for money this shouldn't be used. This method is only here for the Bimpf import.

func NewMonyFromDotNotation

func NewMonyFromDotNotation(value, code string) (Money, error)

func NewMonyFromParse

func NewMonyFromParse(value string) (Money, error)

func (Money) MarshalYAML

func (m Money) MarshalYAML() (interface{}, error)

func (Money) String

func (m Money) String() string

func (*Money) UnmarshalYAML

func (m *Money) UnmarshalYAML(value *yaml.Node) error

func (Money) Value

func (m Money) Value() string

type Report

type Report struct {
	Title           string
	ColumnTitles    []string
	ValidateResults ValidateResults
}

func (Report) Render

func (r Report) Render() string

Render returns the report as a string.

func (Report) Write

func (r Report) Write(pth string)

Write renders the Report and writes it to the given path.

type SearchItem

type SearchItem struct {
	Name        string
	Type        string
	Value       interface{}
	SearchValue string
}

type SearchItems

type SearchItems []SearchItem

func (SearchItems) ByIndex

func (s SearchItems) ByIndex(index int) (*SearchItem, error)

func (SearchItems) Match

func (s SearchItems) Match(search string) SearchItems

type Strategy

type Strategy int
const (
	AcceptStrategy Strategy = iota
	RedoStrategy
	SkipStrategy
)

func AskForStategy

func AskForStategy() Strategy

type Table

type Table struct {
	Header TableRow
	Rows   []TableRow
}

func (Table) Render

func (t Table) Render() string

type TableRow

type TableRow []string

func (TableRow) Render

func (r TableRow) Render(widths map[int]int) string

type TransactionType

type TransactionType int
const (
	CreditTransaction TransactionType = iota // Incoming transaction
	DebitTransaction                         // Outgoing transaction
)

type Validatable

type Validatable interface {
	Type() string
	String() string
	Conditions() Conditions
}

Validatable types can be validated.

type ValidateResult

type ValidateResult struct {
	Element    Validatable
	Conditions Conditions
}

ValidateResult contains the result of a validation check.

func Check

func Check(v Validatable) ValidateResult

Check the Validatable and return the results.

func (ValidateResult) Log

func (v ValidateResult) Log()

Log logs all validation

func (ValidateResult) String

func (v ValidateResult) String() string

func (ValidateResult) TableRows

func (v ValidateResult) TableRows() [][]string

func (ValidateResult) Valid

func (v ValidateResult) Valid() bool

Valid returns true if there were no validation problems.

type ValidateResults

type ValidateResults []ValidateResult

func (ValidateResults) String

func (v ValidateResults) String() string

func (ValidateResults) TableRows

func (v ValidateResults) TableRows() [][]string

Jump to

Keyboard shortcuts

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