util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package util util consists of general utility functions and structures.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDollar

func AddDollar(s string) string

AddDollar prepends a dollar sign to the string if it

func Contains

func Contains(value string, ar []string) bool

Contains checks for the existence of the passed value in the array

func ContainsS

func ContainsS(value string, ar []string) string

ContainsS checks for the existence of the passed value in the array

func Dashed

func Dashed(str string) string

Dashed returns the string "-" if passed string is empty.

func Difference

func Difference(a, b []string) []string

Difference substitues the array of strings b from a

func Example

func Example(s string) string

Example normalizes the example section

func GetInt

func GetInt(value interface{}) (result int)

GetInt returns the int value for the passed value or -1 for invalid input.

func GetString

func GetString(value interface{}) (result string)

GetString accepts a value and tries to return a string representation. If a conversion is not possible, then this function returns an error.

func LoadPrivateKeyPEM

func LoadPrivateKeyPEM(path string) (*rsa.PrivateKey, error)

LoadPrivateKeyPEM reads the private key from the passed file in PEM format.

func LocalTimeStr

func LocalTimeStr(str string) string

LocalTimeStr converts time string in RFC3339 to local time in RFC822

func LocalTimeStrCustom

func LocalTimeStrCustom(str, fmt string) string

LocalTimeStrCustom converts time string in RFC3339 to local time in custom format

func LongDesc

func LongDesc(s string) string

LongDesc normalizes the long description

func Par

func Par(pairs ...string) string

Par takes a list of name value pairs and builds a url parameter list

func Plural

func Plural(str string) string

Plural generates the English plural of the passed string

func RemoveQuotes

func RemoveQuotes(s string) string

RemoveQuotes removes embracing quotes, e.g. "hello" becomes hello and 'world' becomes world

Types

type Claim

type Claim struct {
	Iss string // iss (issuer):identifies the principal that issued the JWT
	Sub string // sub (subject): identifies the principal that is the subject of the JWT
	Aud string // aud (audience): identifies the recipients that the JWT is intended for
}

Claim contains the three regisitered claims required for authentication. See https://tools.ietf.org/html/rfc7519 for more details.

func (*Claim) JWT

func (claim *Claim) JWT(key *rsa.PrivateKey) (string, error)

JWT calculates the signature of the claim and returns the JSON Web Token.

type Column

type Column struct {
	Number int
	Name   string
	Cells  []interface{}
	Calc   func(interface{}) interface{}
}

Column represents one column in a table

type GlobalConfig

type GlobalConfig struct {
	Name   string
	Config string
	Debug  bool
	Human  bool
}

GlobalConfig contains the global configuration

func NewGlobalConfig

func NewGlobalConfig(name string, cmd *cobra.Command) *GlobalConfig

NewGlobalConfig returns an initilized configuration.

func (*GlobalConfig) Configure

func (o *GlobalConfig) Configure(cmd *cobra.Command) error

Configure loads the configuration file encoded in json or yaml.

func (*GlobalConfig) GetPreRunE

func (o *GlobalConfig) GetPreRunE() func(*cobra.Command, []string) error

GetPreRunE returns the function for PreRunE function of cobra.Comamand

type JSONCache

type JSONCache struct {
	// contains filtered or unexported fields
}

JSONCache stores json objects in a file

func NewJSONCache

func NewJSONCache(path func() []string) *JSONCache

NewJSONCache returns an initialzed JSONCache object

func (*JSONCache) Invalidate

func (jc *JSONCache) Invalidate()

Invalidate invalidates the cache by deleting the related file

func (*JSONCache) Load

func (jc *JSONCache) Load(obj interface{}) error

Load loads the json file into the passed object

func (*JSONCache) Save

func (jc *JSONCache) Save(obj interface{}) error

Save stores the passed object in json format to a file

type KVCache

type KVCache struct {
	// contains filtered or unexported fields
}

KVCache is a key value cache for strings with optional persistence

func NewKVCache

func NewKVCache(cacheRead, cacheWrite func() bool, exec func() (map[string]string, error), path func() []string) *KVCache

NewKVCache creates an initialized KVCache object

func (*KVCache) GetValue

func (l *KVCache) GetValue(key string) string

GetValue returns the value for the passed key. If no value could be retrieved then the key will be returned.

func (*KVCache) GetValueE

func (l *KVCache) GetValueE(key string) (string, error)

GetValueE returns the value for the passed key. If no value could be retrieved then an error will be returned.

func (*KVCache) Invalidate

func (l *KVCache) Invalidate()

Invalidate invalidates the cache

func (*KVCache) Keys

func (l *KVCache) Keys() ([]string, error)

Keys returns a list of keys

func (*KVCache) Load

func (l *KVCache) Load() (*KVCacheData, error)

Load loads the cache

func (*KVCache) MapValues

func (l *KVCache) MapValues(m func(string) string)

MapValues calls the passed function for each value and stores the result

func (*KVCache) Remove

func (l *KVCache) Remove(key string)

Remove removes the string with the passed key

func (*KVCache) Values

func (l *KVCache) Values() ([]string, error)

Values returns a list of values

type KVCacheData

type KVCacheData struct {
	Map     map[string]string
	Expires time.Time
}

KVCacheData stores the data of the KVCache with an expiry date

func (*KVCacheData) Get

func (c *KVCacheData) Get(key string) string

Get returns the value for the passed key. If no value could be found then the key will be returned.

func (*KVCacheData) GetE

func (c *KVCacheData) GetE(key string) (string, error)

GetE returns the value for the passed key. If no value could be found then an error will be returned.

func (*KVCacheData) Keys

func (c *KVCacheData) Keys() []string

Keys returns a list of keys

func (*KVCacheData) ValidIn

func (c *KVCacheData) ValidIn(d time.Duration) bool

ValidIn in checks if the token is still valid for passed duration

func (*KVCacheData) Values

func (c *KVCacheData) Values() []string

Values returns a list of values

type LazyPath

type LazyPath struct {
	// contains filtered or unexported fields
}

LazyPath builds a path on the first call

func NewLazyPath

func NewLazyPath(exec func() []string) *LazyPath

NewLazyPath returns an initialized LazyPath object

func (*LazyPath) Full

func (lp *LazyPath) Full() []string

Full returns the full path

func (*LazyPath) Name

func (lp *LazyPath) Name() string

Name returns the name of the file

func (*LazyPath) Path

func (lp *LazyPath) Path() []string

Path returns the path component

type Mapper

type Mapper map[string]string

Mapper is a map of strings

func (Mapper) Get

func (m Mapper) Get(key string) string

Get returns the value for the passed key. If no value can be found the key will be returned.

func (Mapper) GetL

func (m Mapper) GetL(key string) string

GetL normalizes the key to lower case before getting the value. If no value can be found the original key will be returned.

func (Mapper) Invert

func (m Mapper) Invert() Mapper

Invert creats a new mapper with inverted key value relation. Key -> Value becomes Value -> Key.

func (Mapper) Keys

func (m Mapper) Keys() []string

Keys returns a list of keys

type ObjectCache

type ObjectCache struct {
	// contains filtered or unexported fields
}

ObjectCache is an object cache

func NewObjectCache

func NewObjectCache(f func() ([]interface{}, error)) *ObjectCache

NewObjectCache creates an initialized ObjectCache object

func (*ObjectCache) Load

func (c *ObjectCache) Load() (*ObjectCacheData, error)

Load loads the cache

func (*ObjectCache) Mapper

func (c *ObjectCache) Mapper(key, value []string) Mapper

Mapper converts the stored objects to a Mapper. Parameters key and value are Query paths to the desired object attributes.

type ObjectCacheData

type ObjectCacheData struct {
	Map     []interface{}
	Expires time.Time
}

ObjectCacheData stores the objects

func (*ObjectCacheData) Valid

func (c *ObjectCacheData) Valid() bool

Valid in checks if the token is still valid for passed duration

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query supports queries on raw json objects

func NewQuery

func NewQuery(obj interface{}) *Query

NewQuery creates an initialized query object

func (*Query) Concat

func (q *Query) Concat(separator string, rf func(*Query) string) string

Concat calls the passed function on all children and concatenates the results separated by the passed separator.

func (*Query) Get

func (q *Query) Get(index int) *Query

Get returns the children at the passed index

func (*Query) Int

func (q *Query) Int(path ...string) int

Int returns the integer of the referenced path

func (*Query) Interface

func (q *Query) Interface() interface{}

Interface returns the current object

func (*Query) Len

func (q *Query) Len(path ...string) int

Len returns the length of the referenced path

func (*Query) Length

func (q *Query) Length() int

Length returns the length of the current object

func (*Query) Path

func (q *Query) Path(path ...string) *Query

Path queries nested objects, e.g. property a.b.c will be queried with Path("a","b","c")

func (*Query) Range

func (q *Query) Range(rf func(*Query))

Range executes the passed function on all children of the current object

func (*Query) RangeAttributes

func (q *Query) RangeAttributes(rf func(string, *Query))

RangeAttributes executes the passed function on all children of the current object

func (*Query) RangeI

func (q *Query) RangeI(rf func(int, *Query))

RangeI executes the passed function on all children of the current object. It provides the index of the object.

func (*Query) Str

func (q *Query) Str(path ...string) string

Str returns the string of the referenced path

func (*Query) String

func (q *Query) String() string

String returns the current object as string

func (*Query) Strings

func (q *Query) Strings() []string

Strings returns the current object as array of strings

func (*Query) Value

func (q *Query) Value(path ...string) interface{}

Value returns the object of the referenced path

type StringCache

type StringCache struct {
	// contains filtered or unexported fields
}

StringCache is a string cache

func NewStringCache

func NewStringCache(cacheRead, cacheWrite func() bool, exec func() ([]string, error), path func() []string) *StringCache

NewStringCache creates an initialized StringCache object

func (*StringCache) GetList

func (l *StringCache) GetList() ([]string, error)

GetList returns all stored values

func (*StringCache) Load

func (l *StringCache) Load() (*StringCacheData, error)

Load loads the cache

type StringCacheData

type StringCacheData struct {
	List    []string
	Expires time.Time
}

StringCacheData stores a list of strings with expiry date

func (*StringCacheData) ValidIn

func (c *StringCacheData) ValidIn(d time.Duration) bool

ValidIn in checks if the list is still valid for passed duration

type Table

type Table struct {
	Columns    []*Column
	Height     int
	Width      int
	HideHeader bool
	// contains filtered or unexported fields
}

Table contains any object represented as table

func NewTable

func NewTable(names []string, capacity int) *Table

NewTable creates a new initialized table with column names and initial capacity

func (*Table) Append

func (t *Table) Append(row map[string]interface{})

Append appends a new row to the end of the table

func (*Table) Array

func (t *Table) Array() [][]interface{}

Array converts the table to a two-dimensional array (row x column)

func (*Table) Column

func (t *Table) Column(name string) *Column

Column returns the column with the passed name

func (*Table) Get

func (t *Table) Get(row, col int) interface{}

Get returns the cell value for the passed coordinations

func (*Table) Print

func (t *Table) Print(out io.Writer)

Print prints the table to the passed io.Writer

Jump to

Keyboard shortcuts

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