util

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: BSD-3-Clause, Apache-2.0 Imports: 37 Imported by: 16

README

Resources

  • k8s.io/utils/
  • k8s.io/apiserver/pkg/util/
  • k8s.io/client-go/util/

Documentation

Overview

from aws-sdk-go

  • export ETCDCTL_API=3
  • etcdctl get --prefix /openfalcon

Index

Constants

View Source
const (
	B  ByteSize = 1
	KB          = B << 10
	MB          = KB << 10
	GB          = MB << 10
	TB          = GB << 10
	PB          = TB << 10
	EB          = PB << 10
)
View Source
const (
	TIME_F_SIMPLE = "2006-01-02 15:04:05"
	TIME_F_STD    = "2006-01-02 15:04:05 -07"
	DATE_F_STD    = "2006-01-02"
	TIME_M        = int64(60)
	TIME_H        = int64(60 * 60)
	TIME_D        = int64(60 * 60 * 24)
)
View Source
const (
	IndentSize = 4
)
View Source
const (
	NotAvailable = "-"
)

Variables

View Source
var (
	IpExp      = regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+`)
	AddrExp    = regexp.MustCompile(`^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)?:[0-9]+`)
	NumExp     = regexp.MustCompile(`^0x[0-9a-fA-F]+|^[0-9]+`)
	KeywordExp = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9-_]+`)
	TextExp    = regexp.MustCompile(`(^"[^"]+")|(^[^"\n \t;]+)`)
	EnvExp     = regexp.MustCompile(`\$\{[a-zA-Z][0-9a-zA-Z_]+\}`)
	NameExp    = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9-_\.]*$`)
	NameExp2   = regexp.MustCompile(`^[a-z][a-z0-9-]*$`)
	NameExp3   = regexp.MustCompile(`^[a-z][a-z0-9:]*$`)
	PathExp    = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9-_\.]*(\/[a-zA-Z0-9_][a-zA-Z0-9-_\.]*)*$`)
)
View Source
var (
	ErrDryRun = errors.New("dry run")
)
View Source
var (
	ErrUnsupported = errors.New("Unsupported")
)

Functions

func AddrIsDisable

func AddrIsDisable(addr string) bool

func Atob

func Atob(str string, def ...bool) bool

func Atoi

func Atoi(str string, def ...int) int

str, def, max

func Atoi64

func Atoi64(str string, def ...int) int64

func Backtraces

func Backtraces()

func Base64Decode

func Base64Decode(in string) ([]byte, error)

func Base64Encode

func Base64Encode(in []byte) string

func Bash

func Bash(script []byte) ([]byte, error)

func Bool

func Bool(v bool) *bool

Bool returns a pointer to the bool value passed in.

func BoolMap

func BoolMap(src map[string]bool) map[string]*bool

BoolMap converts a string map of bool values into a string map of bool pointers

func BoolSlice

func BoolSlice(src []bool) []*bool

BoolSlice converts a slice of bool values into a slice of bool pointers

func BoolValue

func BoolValue(v *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func BoolValueMap

func BoolValueMap(src map[string]*bool) map[string]bool

BoolValueMap converts a string map of bool pointers into a string map of bool values

func BoolValueSlice

func BoolValueSlice(src []*bool) []bool

BoolValueSlice converts a slice of bool pointers into a slice of bool values

func Byte added in v0.0.2

func Byte(v byte) *byte

func ByteValue added in v0.0.2

func ByteValue(v *byte) byte

func Caller

func Caller(n int) string

func CamelCasedName

func CamelCasedName(in string) string

convert like this: "hello_world" to "HelloWorld"

func CheckCmds

func CheckCmds(cmds ...string) error

func CheckDir

func CheckDir(dir string, mk bool) error

func CheckDirName

func CheckDirName(name string) error

func CheckDirs

func CheckDirs(dirs ...string) error

func CheckGroupName

func CheckGroupName(name string) error

func CheckName

func CheckName(name string) error

func CheckPath

func CheckPath(name string) error

func CheckRoleName

func CheckRoleName(name string) error

func CheckScopeName

func CheckScopeName(name string) error

func CleanSockFile

func CleanSockFile(net, addr string) (string, string)

func Dialer

func Dialer(addr string, timeout time.Duration) (net.Conn, error)

func Diff

func Diff(src, dst []string) (add, del []string)

func Diff2Map

func Diff2Map(pre, now interface{}) map[string]interface{}

func Diff3

func Diff3(src, dst []string) (add, del, eq []string)

func EnvDef

func EnvDef(key, defaultValue string) string

func EnvVarFilter

func EnvVarFilter(data []byte) []byte

Environment Variables $HOME value instead of ${HOME}

func Error

func Error(err error) string

func ErrorString

func ErrorString(err error) *string

func Errorf

func Errorf(format string, args ...interface{}) error

func Exec

func Exec(name string, arg ...string) error

func FileMd5sum

func FileMd5sum(file string) (string, error)

func Filepath

func Filepath(name string) (string, error)

func FirstLine

func FirstLine(in string) string

func Float32 added in v0.0.2

func Float32(v float32) *float32

func Float32Value added in v0.0.2

func Float32Value(v *float32) float32

func Float64

func Float64(v float64) *float64

Float64 returns a pointer to the float64 value passed in.

func Float64Map

func Float64Map(src map[string]float64) map[string]*float64

Float64Map converts a string map of float64 values into a string map of float64 pointers

func Float64Slice

func Float64Slice(src []float64) []*float64

Float64Slice converts a slice of float64 values into a slice of float64 pointers

func Float64Value

func Float64Value(v *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func Float64ValueMap

func Float64ValueMap(src map[string]*float64) map[string]float64

Float64ValueMap converts a string map of float64 pointers into a string map of float64 values

func Float64ValueSlice

func Float64ValueSlice(src []*float64) []float64

Float64ValueSlice converts a slice of float64 pointers into a slice of float64 values

func FmtTs

func FmtTs(ts int64, verbose ...bool) string

func FromNow

func FromNow(s int64) string

FromNow return relative time with current time

func FromNowAbs

func FromNowAbs(s int64) string

func GetArticleForNoun

func GetArticleForNoun(noun string, padding string) string

GetArticleForNoun returns the article needed for the given noun.

func GetIPAddress

func GetIPAddress(r *http.Request) string

GetIPAddress "X-Forwarded-For", "X-Real-Ip", req.RemoteAddr

func GetName

func GetName(v interface{}) string

func GetPeerAddrFromCtx

func GetPeerAddrFromCtx(ctx context.Context) (string, error)

GetPeerAddrFromCtx try to return peer address from grpc context

func GetRemoteIP

func GetRemoteIP(remoteAddr string) (net.IP, error)

GetRemoteIp host:port "192.0.2.1:25", "[2001:db8::1]:80"

func GetType

func GetType(v interface{}) string

func GetUGroups

func GetUGroups(username string) ([]uint32, error)

func GetValue

func GetValue(rv reflect.Value) (data []string, err error)

func IPContains

func IPContains(ip net.IP, network string) bool

func IndentLines

func IndentLines(i int, lines string) (ret string)

func Int

func Int(v int) *int

Int returns a pointer to the int value passed in.

func Int16 added in v0.0.2

func Int16(v int16) *int16

func Int16Value added in v0.0.2

func Int16Value(v *int16) int16

func Int32 added in v0.0.2

func Int32(v int32) *int32

func Int32Value added in v0.0.2

func Int32Value(v *int32) int32

func Int64

func Int64(v int64) *int64

func Int64Map

func Int64Map(src map[string]int64) map[string]*int64

Int64Map converts a string map of int64 values into a string map of int64 pointers

func Int64Slice

func Int64Slice(src []int64) []*int64

Int64Slice converts a slice of int64 values into a slice of int64 pointers

func Int64Value

func Int64Value(v *int64) int64

func Int64ValueMap

func Int64ValueMap(src map[string]*int64) map[string]int64

Int64ValueMap converts a string map of int64 pointers into a string map of int64 values

func Int64ValueSlice

func Int64ValueSlice(src []*int64) []int64

Int64ValueSlice converts a slice of int64 pointers into a slice of int64 values

func Int8 added in v0.0.2

func Int8(v int8) *int8

func Int8Value added in v0.0.2

func Int8Value(v *int8) int8

func IntMap

func IntMap(src map[string]int) map[string]*int

IntMap converts a string map of int values into a string map of int pointers

func IntRange

func IntRange(a, b, c int) int

func IntSlice

func IntSlice(src []int) []*int

IntSlice converts a slice of int values into a slice of int pointers

func IntValue

func IntValue(v *int) int

IntValue returns the value of the int pointer passed in or 0 if the pointer is nil.

func IntValueMap

func IntValueMap(src map[string]*int) map[string]int

IntValueMap converts a string map of int pointers into a string map of int values

func IntValueSlice

func IntValueSlice(src []*int) []int

IntValueSlice converts a slice of int pointers into a slice of int values

func IsDir

func IsDir(file string) bool

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

func IsFile

func IsFile(file string) bool

func JsonStr

func JsonStr(in interface{}, pretty ...bool) string

func JsonTab

func JsonTab(in interface{}, minwidth, tabwidth, padding int, padchar byte, flags uint) ([]byte, error)

JsonTabStr(f, 0, 0, 2, ' ', tabwriter.TabIndent)

func JsonTabStr

func JsonTabStr(in interface{}, minwidth, tabwidth, padding int, padchar byte, flags uint) (string, error)

func Kill

func Kill(pid int, sig syscall.Signal) (err error)

func KvMask

func KvMask(s string) string

ab=cd => ab=***

func LastLine

func LastLine(in string) string

func LowerCamelCasedName

func LowerCamelCasedName(in string) string

convert like this: "hello_world" to "helloWorld"

func MakeSlice

func MakeSlice(v interface{}) interface{}

MakeSlice return a slice of input

func Md5sum

func Md5sum(raw []byte) string

func MergeMapString

func MergeMapString(in ...map[string]string) map[string]string

func MillisecondsTimeValue

func MillisecondsTimeValue(v *int64) time.Time

MillisecondsTimeValue converts an int64 pointer to a time.Time value representing milliseconds sinch Epoch or time.Time{} if the pointer is nil.

func MustJsonTabStr

func MustJsonTabStr(in interface{}, minwidth, tabwidth, padding int, padchar byte, flags uint) string

func NewStructPtr

func NewStructPtr(in interface{}) interface{}

func Now

func Now() int64

func NowPtr

func NowPtr(delta ...int64) *int64

func ParseAddr

func ParseAddr(url string) (net, addr string)

func ParseDate

func ParseDate(value *string, hour, min, sec int) (*int64, error)

func Popen

func Popen(timeout time.Duration, dryRun bool, cmd string, args ...string) (string, error)

func PrepareValue

func PrepareValue(rv reflect.Value, rt reflect.Type)

func Prettify

func Prettify(i interface{}) string

Prettify returns the string representation of a value.

func PrettyTab

func PrettyTab(in string) string

func Printable

func Printable(in interface{}) bool

func RandInt

func RandInt() int

func RandInt64

func RandInt64() int64

func RandString

func RandString(n int) string

func ReadFile

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

func ReadFileInt

func ReadFileInt(filename string) (int, error)

func ReadFileTo64

func ReadFileTo64(url string) (*string, error)

func SecondsTimeValue

func SecondsTimeValue(v *int64) time.Time

SecondsTimeValue converts an int64 pointer to a time.Time value representing seconds since Epoch or time.Time{} if the pointer is nil.

func SetContentType

func SetContentType(header http.Header, contentType string) error

func SetValue

func SetValue(rv reflect.Value, data []string) error

func Sha1sum

func Sha1sum(raw []byte) string

func SizeOf

func SizeOf(v string) uint64

func SizeReadable

func SizeReadable(b int) string

func SnakeCasedName

func SnakeCasedName(name string) string

func Split

func Split(s string, c string, cutc bool) (string, string)

Maybe s is of the form t c u. If so, return t, c u (or t, u if cutc == true). If not, return s, "".

func SrcAddr

func SrcAddr(addr net.IPAddr) net.IP

func SrcAddrV4

func SrcAddrV4(a, b, c, d byte) net.IP

func SrcAddrs

func SrcAddrs(addrs []net.IPAddr) []net.IP

srcsAddrs tries to UDP-connect to each address to see if it has a route. (This doesn't send any packets). The destination port number is irrelevant.

func String

func String(v string) *string

String returns a pointer to the string value passed in.

func StringArrayContains

func StringArrayContains(needle string, haystack []string) bool

func StringMap

func StringMap(src map[string]string) map[string]*string

StringMap converts a string map of string values into a string map of string pointers

func StringSlice

func StringSlice(src []string) []*string

StringSlice converts a slice of string values into a slice of string pointers

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

func StringValueMap

func StringValueMap(src map[string]*string) map[string]string

StringValueMap converts a string map of string pointers into a string map of string values

func StringValueSlice

func StringValueSlice(src []*string) []string

StringValueSlice converts a slice of string pointers into a slice of string values

func Strings2MapBool

func Strings2MapBool(ss []string) map[string]bool

func Strings2MapString

func Strings2MapString(ss []string, in ...map[string]string) map[string]string

ss > in[n] > in[n-1] > ... > in[0]

func StructConv

func StructConv(in, out interface{}) interface{}

func StructCopy

func StructCopy(dst, src interface{}) error

func StructMd5

func StructMd5(in interface{}) (string, error)

func SubStr

func SubStr(in string, begin, end int) string

SubStr is Safe SubStr

func SubStr2

func SubStr2(in string, begin, end int) string

SubStr2 return [begin, end)...

func SubStr3

func SubStr3(in string, pre, suf int) string

SubStr3 return [0:pre]...[suf:len]

func Sum32

func Sum32(raw []byte) uint32

func Sum64

func Sum64(raw []byte) uint64

func Table

func Table(in interface{}) []byte

func TableStr

func TableStr(in interface{}) string

func Time

func Time(v time.Time) *time.Time

Time returns a pointer to the time.Time value passed in.

func TimeMap

func TimeMap(src map[string]time.Time) map[string]*time.Time

TimeMap converts a string map of time.Time values into a string map of time.Time pointers

func TimeOf

func TimeOf(v string) int64

func TimeSlice

func TimeSlice(src []time.Time) []*time.Time

TimeSlice converts a slice of time.Time values into a slice of time.Time pointers

func TimeUnixMilli

func TimeUnixMilli(t time.Time) int64

TimeUnixMilli returns a Unix timestamp in milliseconds from "January 1, 1970 UTC". The result is undefined if the Unix time cannot be represented by an int64. Which includes calling TimeUnixMilli on a zero Time is undefined.

This utility is useful for service API's such as CloudWatch Logs which require their unix time values to be in milliseconds.

See Go stdlib https://golang.org/pkg/time/#Time.UnixNano for more information.

func TimeValue

func TimeValue(v *time.Time) time.Time

TimeValue returns the value of the time.Time pointer passed in or time.Time{} if the pointer is nil.

func TimeValueMap

func TimeValueMap(src map[string]*time.Time) map[string]time.Time

TimeValueMap converts a string map of time.Time pointers into a string map of time.Time values

func TimeValueSlice

func TimeValueSlice(src []*time.Time) []time.Time

TimeValueSlice converts a slice of time.Time pointers into a slice of time.Time values

func TitleCasedName

func TitleCasedName(name string, lower bool) string

convert like this: "hello_world" to "HelloWorld"

func ToScope

func ToScope(scope *string) (ret map[string]bool)

ToScope transport strings fields into map[string]bool format

func ToScopeStr

func ToScopeStr(scope map[string]bool) *string

func Uint added in v0.0.2

func Uint(v uint) *uint

func Uint16 added in v0.0.2

func Uint16(v uint16) *uint16

func Uint16Value added in v0.0.2

func Uint16Value(v *uint16) uint16

func Uint32 added in v0.0.2

func Uint32(v uint32) *uint32

func Uint32Value added in v0.0.2

func Uint32Value(v *uint32) uint32

func Uint64 added in v0.0.2

func Uint64(v uint64) *uint64

func Uint64Value added in v0.0.2

func Uint64Value(v *uint64) uint64

func Uint8 added in v0.0.2

func Uint8(v uint8) *uint8

func Uint8Value added in v0.0.2

func Uint8Value(v *uint8) uint8

func UintValue added in v0.0.2

func UintValue(v *uint) uint

func Until

func Until(f func(), interval time.Duration, stopCh <-chan struct{})

func UntilWithTick

func UntilWithTick(f func(), c <-chan time.Time, stopCh <-chan struct{})

func Username

func Username() string

func Write

func Write(w io.Writer, b []byte) error

func WriteTempFile

func WriteTempFile(dir, pattern string, content []byte) (string, error)

func YamlStr added in v0.0.2

func YamlStr(in interface{}) string

Types

type ByteSize

type ByteSize uint64

func (ByteSize) Bytes

func (b ByteSize) Bytes() uint64

func (ByteSize) EBytes

func (b ByteSize) EBytes() float64

func (ByteSize) GBytes

func (b ByteSize) GBytes() float64

func (ByteSize) HR

func (b ByteSize) HR() string

func (ByteSize) HumanReadable

func (b ByteSize) HumanReadable() string

func (ByteSize) KBytes

func (b ByteSize) KBytes() float64

func (ByteSize) MBytes

func (b ByteSize) MBytes() float64

func (ByteSize) PBytes

func (b ByteSize) PBytes() float64

func (ByteSize) String

func (b ByteSize) String() string

func (ByteSize) TBytes

func (b ByteSize) TBytes() float64

type Cmd

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

func New

func New(name string) *Cmd

func (*Cmd) Args

func (p *Cmd) Args(args ...string) *Cmd

func (*Cmd) Env

func (p *Cmd) Env(key, value string) *Cmd

func (*Cmd) Run

func (p *Cmd) Run() error

func (*Cmd) String

func (p *Cmd) String() string

type DiffEntity

type DiffEntity interface {
	Key() string
}

func Diff4

func Diff4(src, dst []DiffEntity) (add, del, eq []DiffEntity)

type Duration

type Duration time.Duration

func (Duration) Duration

func (d Duration) Duration() time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) (err error)

type Parser

type Parser interface {
	Parse(in string) error
}

type Preparer

type Preparer interface {
	Prepare()
}

Directories

Path Synopsis
"github.com/docker/docker/pkg/broadcaster"
"github.com/docker/docker/pkg/broadcaster"
Package connrotation implements a connection dialer that tracks and can close all created connections.
Package connrotation implements a connection dialer that tracks and can close all created connections.
Package daemon provides a Go implementation of the sd_notify protocol.
Package daemon provides a Go implementation of the sd_notify protocol.
Package framer implements simple frame decoding techniques for an io.ReadCloser
Package framer implements simple frame decoding techniques for an io.ReadCloser
golang
net
reflect
Package reflect is a fork of go's standard library reflection package, which allows for deep equal with equality functions defined.
Package reflect is a fork of go's standard library reflection package, which allows for deep equal with equality functions defined.
template
This package is copied from Go library text/template.
This package is copied from Go library text/template.
Package inotify implements a wrapper for the Linux inotify system.
Package inotify implements a wrapper for the Linux inotify system.
Package journal provides write bindings to the local systemd journal.
Package journal provides write bindings to the local systemd journal.
Package keyutil contains utilities for managing public/private key pairs.
Package keyutil contains utilities for managing public/private key pairs.
net
ebtables
Package ebtables allows to control the ebtables Linux-based bridging firewall.
Package ebtables allows to control the ebtables Linux-based bridging firewall.
Package process provides functions for inspecting processes.
Package process provides functions for inspecting processes.
Package rand provides utilities related to randomization.
Package rand provides utilities related to randomization.
types
Package types just provides input types to the set generator.
Package types just provides input types to the set generator.

Jump to

Keyboard shortcuts

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