vcmn

package
v0.0.0-...-3b984fc Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 23 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskPassword

func AskPassword(name string) (secret string)

AskPassword - asks password, prints the given name before asking

func Decrypt

func Decrypt(key []byte, text string) (decrypted string, err error)

Decrypt - decrypts input text with given key using AES algo

func DecryptStr

func DecryptStr(key string, text string) (decrypted string, err error)

DecryptStr - AES decrypts input text with given key string

func DumpJSON

func DumpJSON(o interface{})

DumpJSON - dumps JSON representation of given data to stdout

func Encrypt

func Encrypt(key []byte, text string) (encrypted string, err error)

Encrypt - encrypts input text with given key using AES algo

func EncryptStr

func EncryptStr(key string, text string) (encrypted string, err error)

EncryptStr - AES encrypts input text with given key string

func ErrString

func ErrString(err error) string

ErrString - returns the error string if the given error is not nil

func ExistsAsDir

func ExistsAsDir(path string) (yes bool)

ExistsAsDir - checks if a directory exists at given path. If a error occurs while stating whatever exists at given location, false is returned

func ExistsAsFile

func ExistsAsFile(path string) (yes bool)

ExistsAsFile - checks if a regular file exists at given path. If a error occurs while stating whatever exists at given location, false is returned

func FirstValid

func FirstValid(errs ...error) (err error)

FirstValid - returns the first error that is not nil

func GetAsJSON

func GetAsJSON(o interface{}) (jstr string, err error)

GetAsJSON - converts given data to JSON and returns as pretty printed

func GetConfig

func GetConfig(key string, value interface{}) (err error)

GetConfig - retrieves config value for the given key and populates the value argument given. If the key does not exist in the config map or if its not possible to populate value arg from retrieved value and error is returned

func GetExecDir

func GetExecDir() (dirPath string)

GetExecDir - gives absolute path of the directory in which the executable for the current application is present

func GetFirstValidStr

func GetFirstValidStr(strs ...string) (str string)

GetFirstValidStr - gets first string that is not empty

func GetStringConfig

func GetStringConfig(key string) (value string)

GetStringConfig - gets a value associated with config key

func HasConfig

func HasConfig(key string) (yes bool)

HasConfig - checks if a value exists in config for a key

func Hash

func Hash(in string) (out string)

Hash - creates a SHA1 hash of input string

func LoadConfig

func LoadConfig(appName string)

LoadConfig - loads configuration for app with given appName. Searches for configuration file in standard locations and loads based all of them. If same config values is present in different files, value for the file that is loaded last is kept

func PrintConfig

func PrintConfig()

PrintConfig - prints the configuration

Types

type ArgGetter

type ArgGetter struct {
	Err error
	// contains filtered or unexported fields
}

ArgGetter - this struct and its method are helpers to combine getting args from commandline arguments or from reading from console. Also handles errors when required arguments are not provided

func NewArgGetter

func NewArgGetter(ctx *cli.Context) (argtr *ArgGetter)

NewArgGetter - creates a new argument retriever with given context

func (*ArgGetter) GetBool

func (retriever *ArgGetter) GetBool(key string) (val bool)

GetBool - gives a Boolean argument either from commandline or from blocking user input, this method doesnt complain even if the arg-value is empty

func (*ArgGetter) GetInt

func (retriever *ArgGetter) GetInt(key string) (val int)

GetInt - gives a Integer argument either from commandline or from blocking user input, this method doesnt complain even if the arg-value is empty

func (*ArgGetter) GetOptionalInt

func (retriever *ArgGetter) GetOptionalInt(key string) (val int)

GetOptionalInt - retrieves int from commandline, if not provided it wont ask again from stdin

func (*ArgGetter) GetOptionalString

func (retriever *ArgGetter) GetOptionalString(key string) (val string)

GetOptionalString - retrieves string from commandline, if not provided it wont ask again from stdin

func (*ArgGetter) GetRequiredBool

func (retriever *ArgGetter) GetRequiredBool(key string) (val bool)

GetRequiredBool - gives a Boolean argument either from commandline or from blocking user input, this method sets the error if required arg-val is empty

func (*ArgGetter) GetRequiredInt

func (retriever *ArgGetter) GetRequiredInt(key string) (val int)

GetRequiredInt - gives a Integer argument either from commandline or from blocking user input, this method sets the error if required arg-val is empty

func (*ArgGetter) GetRequiredSecret

func (retriever *ArgGetter) GetRequiredSecret(key string) (val string)

GetRequiredSecret - gives a string argument either from commandline or from blocking user input, this method sets the error if required arg-val is empty

func (*ArgGetter) GetRequiredString

func (retriever *ArgGetter) GetRequiredString(key string) (val string)

GetRequiredString - gives a string argument either from commandline or from blocking user input, this method sets the error if required arg-val is empty

func (*ArgGetter) GetString

func (retriever *ArgGetter) GetString(key string) (val string)

GetString - gives a string argument either from commandline or from blocking user input, this method doesnt complain even if the arg-value is empty

type CountList

type CountList struct {
	TotalCount int         `json:"total" bson:"total"`
	Data       interface{} `json:"data" bson:"data"`
}

CountList - paginated list returned from mongoDB along with total number of items in the list counted without pagination

type DateRange

type DateRange struct {
	// Name string    `json:"name" bson:"name"`
	From time.Time `json:"from" bson:"from" sql:"from"`
	To   time.Time `json:"to" bson:"to" sql:"to"`
}

DateRange - represents date ranges

func (*DateRange) IsValid

func (r *DateRange) IsValid() bool

IsValid - returns true if both From and To dates are non-zero

type Filter

type Filter struct {
	Props    map[string]Matcher       `json:"props" bson:"props"`
	Bools    map[string]interface{}   `json:"bools" bson:"bools"`
	Dates    map[string]DateRange     `json:"dates" bson:"dates"`
	Lists    map[string]Matcher       `json:"lists" bson:"lists"`
	Searches map[string][]interface{} `json:"searches" bson:"searches"`
}

Filter - generic filter used to filter data in any mongodb collection

type FilterSpec

type FilterSpec struct {
	Field string     `json:"field" bson:"field"`
	Name  string     `json:"name" bson:"name"`
	Type  FilterType `json:"type" bson:"type"`
}

FilterSpec - filter specification

type FilterSpecList

type FilterSpecList []*FilterSpec

FilterSpecList - alias for array of filter specs

type FilterType

type FilterType string

FilterType - Type of filter item

const Array FilterType = "array'"

Array - filter for an array

const Boolean FilterType = "boolean"

Boolean - filter for boolean field

const Constant FilterType = "constant"

Constant - constant filter value

const Date FilterType = "dateRange"

Date - filter for data range

const Prop FilterType = "prop"

Prop - filter for a value

const Search FilterType = "search"

Search - filter for search text field

const Static FilterType = "static"

Static - constant filter value

type FilterVal

type FilterVal struct {
	Name  string `json:"name" bson:"_id"`
	Count int    `json:"count" bson:"count"`
}

FilterVal - values for filter along with the count

type MatchStrategy

type MatchStrategy string

MatchStrategy - strategy to match multiple fields passed as part of the filters

const MatchAll MatchStrategy = "all"

MatchAll - match all provided values while executing filter

const MatchNone MatchStrategy = "none"

MatchNone - match values that are not part of the provided list while executing filter

const MatchOne MatchStrategy = "one"

MatchOne - match atleast one of the provided values while executing filter

type Matcher

type Matcher struct {
	Strategy MatchStrategy `json:"strategy" bson:"strategy"`
	Fields   []interface{} `json:"fields" bson:"fields"`
}

Matcher - matches the given fields. If multiple fileds are given the; the joining condition is decided by the MatchStrategy given

type Pair

type Pair struct {
	Key   string `json:"key" bson:"key" sql:"key"`
	Value string `json:"value" bson:"value" sql:"value"`
}

Pair - association of key and value

type Param

type Param struct {
	Name    string      `json:"name" bson:"name" sql:"name"`
	Type    ParamType   `json:"type" bson:"type" sql:"type"`
	Desc    string      `json:"desc" bson:"desc" sql:"desc"`
	Range   Range       `json:"range" bson:"range" sql:"range"`
	Choices []Pair      `json:"choices" bson:"choices" sql:"choices"`
	Default interface{} `json:"def" bson:"def" sql:"def"`
}

Param - represents generic parameter

type ParamType

type ParamType int

ParamType - type of the parameter

const (
	//Bool - bool parameter
	Bool ParamType = iota

	//NumberRange - number range parameter
	NumberRange

	//Choice - parameter with choices
	Choice

	//Text - arbitrary string
	Text
)

type PropMatcher

type PropMatcher []interface{}

PropMatcher - matches props

type Range

type Range struct {
	Min int `json:"min" bson:"min" `
	Max int `json:"max" bson:"max"`
}

Range - integer range

type Version

type Version struct {
	Major int `json:"major" bson:"major" sql:"major"`
	Minor int `json:"minor" bson:"minor" sql:"minor"`
	Patch int `json:"patch" bson:"patch" sql:"patch"`
}

Version - represents version of the application

func (Version) String

func (v Version) String() string

String - version to string

Jump to

Keyboard shortcuts

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