util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 20 Imported by: 28

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func ContainsString

func ContainsString(list []string, value string) bool

ContainsString checks if we have a string in a string list

func DecodeYAMLLibObject

func DecodeYAMLLibObject(yamlData interface{}) interface{}

DecodeYAMLLibObject decodes interface format yaml.v2 lib returns map as map[interface{}]interface{} while gohan lib uses map[string]interface{} so we need to convert it here

func ExitFatal

func ExitFatal(a ...interface{})

ExitFatal ...

func ExitFatalf

func ExitFatalf(format string, a ...interface{})

ExitFatalf ...

func ExtendMap

func ExtendMap(original map[string]interface{}, extension map[string]interface{}) map[string]interface{}

ExtendMap extends a map from existing one

func ExtendStringList

func ExtendStringList(original []string, extension []string) []string

ExtendStringList appends a value if it isn't in base list

func GetByJSONPointer

func GetByJSONPointer(inData interface{}, key string) (interface{}, error)

GetByJSONPointer returns subdata of json using json pointer

func GetContent

func GetContent(url string) ([]byte, error)

GetContent loads file from remote or local

func GetEnvMap

func GetEnvMap() map[string]string

GetEnvMap reads environment vars and return key value

func GetSortedKeys

func GetSortedKeys(object map[string]interface{}) []string

GetSortedKeys returns sorted keys of map[string]interface{}

func Index

func Index(slice []string, elem string) int

Index return index of elem in slice

func LoadFile

func LoadFile(filePath string) (interface{}, error)

LoadFile loads object from file. suffix of filepath will be used as file type. currently, json and yaml is supported

func LoadMap

func LoadMap(filePath string) (map[string]interface{}, error)

LoadMap loads map object from file. suffix of filepath will be used as file type. currently, json and yaml is supported

func LoadTemplate

func LoadTemplate(filePath string, params interface{}) (map[string]interface{}, error)

LoadTemplate loads object from file. suffix of filepath will be used as file type. currently, json and yaml is supported

func Match

func Match(a interface{}, b interface{}) bool

Match if a contrains b or a == b

func MatchAsJSON

func MatchAsJSON(expected interface{}) types.GomegaMatcher

MatchAsJSON checks whether the provided arguments are equivalent after being marshalled as JSONs

func MaybeInt

func MaybeInt(value interface{}) int

MaybeInt tries cast to int otherwise returns 0

func MaybeList

func MaybeList(value interface{}) []interface{}

MaybeList tries cast to list otherwise returns empty object

func MaybeMap

func MaybeMap(data interface{}) map[string]interface{}

MaybeMap returns empty map if data is nil

func MaybeString

func MaybeString(data interface{}) string

MaybeString returns "" if data is nil

func MaybeStringList

func MaybeStringList(data interface{}) []string

MaybeStringList returns empty list if data is nil

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func PublicKeyFile

func PublicKeyFile(file string) ssh.AuthMethod

PublicKeyFile read file and return ssh public keys

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func SaveFile

func SaveFile(file string, data interface{}) error

SaveFile saves object to file. suffix of filepath will be used as file type. currently, json and yaml is supported

func TempFile

func TempFile(dir string, prefix string, suffix string) (*os.File, error)

TempFile creates a temporary file with the specified prefix and suffix

Types

type Config

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

Config stores configuration parameters for api server

func GetConfig

func GetConfig() *Config

GetConfig returns configuration data

func (*Config) GetBool

func (config *Config) GetBool(key string, defaultValue bool) bool

GetBool returns string parameter from config

func (*Config) GetInt

func (config *Config) GetInt(key string, defaultValue int) int

GetInt returns int parameter from config

func (*Config) GetList

func (config *Config) GetList(key string, defaultValue []interface{}) []interface{}

GetList returns list parameter from config

func (*Config) GetParam

func (config *Config) GetParam(key string, defaultValue interface{}) interface{}

GetParam returns parameter from config

func (*Config) GetString

func (config *Config) GetString(key, defaultValue string) string

GetString returns string parameter from config

func (*Config) GetStringList

func (config *Config) GetStringList(key string, defaultValue []string) []string

GetStringList returns string list parameter from config

func (*Config) ReadConfig

func (config *Config) ReadConfig(path string) error

ReadConfig reads data from config file Config file can be yaml or json file

type Counter

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

Counter represents atomic counter

func NewCounter

func NewCounter(value int64) *Counter

NewCounter makes atomic counter

func (*Counter) Add

func (counter *Counter) Add(value int64)

Add add value to the counter

func (*Counter) Value

func (counter *Counter) Value() int64

Value get current value

Jump to

Keyboard shortcuts

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