utils

package
v0.0.0-...-d404fe0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	_, Cidr192, _ = net.ParseCIDR("192.168.0.0/16")
	_, Cidr10, _  = net.ParseCIDR("10.0.0.0/8")
	_, Cidr172, _ = net.ParseCIDR("172.16.0.0/19")
	_, Cidr127, _ = net.ParseCIDR("127.0.0.0/8")
	InternalCIDRs = []*net.IPNet{Cidr192, Cidr10, Cidr127, Cidr172}
)

Functions

func AddressIsInternal

func AddressIsInternal(addr net.Addr) bool

func B2S

func B2S(b []byte) string

b2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .

Note it may break if string and/or slice header will change in the future go versions.

func BoolPointer

func BoolPointer(b bool) *bool

func Contains

func Contains(s []string, compare string) bool

func ContainsObjectID

func ContainsObjectID(oid []primitive.ObjectID, compare primitive.ObjectID) bool

func DifferentArray

func DifferentArray(a []string, b []string) bool

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func Int32Pointer

func Int32Pointer(i int32) *int32

func Int64Pointer

func Int64Pointer(i int64) *int64

func IsPointer

func IsPointer(v interface{}) bool

func IsPowerOfTwo

func IsPowerOfTwo(n int64) bool

Util - Is Power Of Two

func IsSliceArray

func IsSliceArray(v interface{}) bool

func IsSliceArrayPointer

func IsSliceArrayPointer(v interface{}) bool

func S2B

func S2B(s string) (b []byte)

S2B converts string to a byte slice without memory allocation.

Note it may break if string and/or slice header will change in the future go versions.

func SliceIndexOf

func SliceIndexOf(s []string, val string) int

func StringPointer

func StringPointer(s string) *string

func Ternary

func Ternary(condition bool, whenTrue interface{}, whenFalse interface{}) interface{}

Util - Ternary: A golang equivalent to JS Ternary Operator

It takes a condition, and returns a result depending on the outcome

Types

type Key

type Key string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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