utils

package
v19.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 18 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPathify

func AbsPathify(inPath string) string

AbsPathify ...

func CIDRToIPv4Range

func CIDRToIPv4Range(cidr string) (string, string, error)

CIDRToIPv4Range converts CIDR to IPv4 range

func CIDRToLongRange

func CIDRToLongRange(cidr string) (uint32, uint32, error)

CIDRToLongRange converts CIDR to range of long values (representing IPv4 addresses)

func Capitalize

func Capitalize(value string) string

Capitalize makes the first letter of the first word uppercased

func Check

func Check(port int) (status bool, err error)

Check if a port is available

func ExtractRetCode

func ExtractRetCode(err error) (string, int, error)

ExtractRetCode extracts info from the error

func GeneratePassword

func GeneratePassword(length uint8) (string, error)

GeneratePassword generates a password with length at least 12

func IPv4ToLong

func IPv4ToLong(ip string) uint32

IPv4ToLong converts IPv4 to uint32

func IsCIDRRoutable

func IsCIDRRoutable(cidr string) (bool, error)

IsCIDRRoutable tells if the network is routable

func IsEmpty

func IsEmpty(v interface{}) bool

IsEmpty checks whether v is an empty struct

func LazyRemove

func LazyRemove(path string) error

LazyRemove is identical to os.Remove, but doesn't raise an error, and log.Warn every error except "file not found" which is ignored

func LongToIPv4

func LongToIPv4(value uint32) string

LongToIPv4 converts uint32 to IP

func New

func New() (port int, err error)

New gets an available port

func Plural

func Plural(value int) string

Plural returns 's' if value > 1, "" otherwise

func UserConfirmed

func UserConfirmed(msg string) bool

UserConfirmed asks user to confirm

Types

type Cache

type Cache interface {
	SetBy(string, func() (interface{}, error)) error
	Set(string, interface{}) error
	ForceSetBy(string, func() (interface{}, error)) error
	ForceSet(string, interface{}) error
	Reset(string) Cache
	Get(string) (interface{}, bool)
	GetOrDefault(string, interface{}) interface{}
}

Cache is an interface for caching elements

func NewMapCache

func NewMapCache() Cache

NewMapCache ...

type MapCache

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

MapCache implements Cache interface using map

func (*MapCache) ForceSet

func (c *MapCache) ForceSet(key string, value interface{}) error

ForceSet ...

func (*MapCache) ForceSetBy

func (c *MapCache) ForceSetBy(key string, by func() (interface{}, error)) error

ForceSetBy ...

func (*MapCache) Get

func (c *MapCache) Get(key string) (value interface{}, ok bool)

Get ...

func (*MapCache) GetOrDefault

func (c *MapCache) GetOrDefault(key string, def interface{}) (value interface{})

GetOrDefault ...

func (*MapCache) Reset

func (c *MapCache) Reset(key string) Cache

Reset ...

func (*MapCache) Set

func (c *MapCache) Set(key string, value interface{}) error

Set ...

func (*MapCache) SetBy

func (c *MapCache) SetBy(key string, by func() (interface{}, error)) error

SetBy ...

type Valid

type Valid interface {
	OK() bool
}

Valid interface is used to check data validity

Jump to

Keyboard shortcuts

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