util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package util provides some additional useful functions not available in GO

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

Abs - non branching Abs function for determine the absolute value of an int

func Abs64

func Abs64(n int64) int64

Abs64 - non branching Abs function for determine the absolute value of an int64

func GcWithStats

func GcWithStats() string

GcWithStats performs a forced garbage collection measuring duration and pre- and post-memory statistics.

func Max

func Max(x, y int) int

Max returns the bigger of the given integers

func Max64

func Max64(x, y int64) int64

Max64 returns the bigger of the given 64-bit integers

func MemStat

func MemStat() string

MemStat returns a string with information about the applications memory usage and GC activity

func Min

func Min(x, y int) int

Min returns the smaller of the given integers

func Min64

func Min64(x, y int64) int64

Min64 returns the smaller of the given 64-bit integers

func Nps

func Nps(nodes uint64, duration time.Duration) uint64

Nps calculates nodes per second from an uint64 and a duration allows zero duration by adding one nanosecond

func ResolveCreateFolder

func ResolveCreateFolder(folderPath string) (string, error)

ResolveCreateFolder is resolving a path to a folder and try to find the folder in a specific set of places. If no folder can be found it will try to create a folder from the last part of the given folder path in the working directory. If a folder can't be created in the working directory it will be created in the os's temp directory. The order will be check like this:

  • if path is absolute it will test if the folder exists or try to create the folder there
  • if path is not absolute we will try finding the folder relative to working directory. If not found we try to create the folder there
  • last we create the folder in temp

func ResolveFile

func ResolveFile(file string) (string, error)

ResolveFile is resolving a path to a file and try to find the file in a specific set of places and then will return an absolute path to it. Path needs to be a file or a not found error will be returned. The order will be check like this:

  • if path is absolute it will return a os specific path and an error if the file does not exist
  • if path is not absolute we will try first
  • relative to working directory
  • relative to executable
  • relative to user home directory

func ResolveFolder

func ResolveFolder(folder string) (string, error)

ResolveFolder is resolving a path to a folder and try to find the folder in a specific set of places and then will return an absolute path to it. Path needs to be a folder or a not found error will be returned. The folder will not be created. The order will be check like this:

  • if path is absolute it will return a os specific path and an error if the file does not exist
  • if path is not absolute we will try first
  • relative to working directory
  • relative to executable
  • relative to user home directory

func TimeTrack

func TimeTrack(start time.Time, name string)

TimeTrack is convenient way to measure timings of function. Usage: defer util.TimeTrack(time.Now(), "some text")

Types

type Bool

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

Bool is a wrapper for atomic operations on bool

func NewBool

func NewBool(initial bool) *Bool

NewBool creates a Bool.

func (*Bool) CAS

func (b *Bool) CAS(old, new bool) bool

CAS is an atomic compare-and-swap.

func (*Bool) Load

func (b *Bool) Load() bool

Load atomically loads the Boolean.

func (*Bool) Store

func (b *Bool) Store(new bool)

Store atomically stores the passed value.

func (*Bool) Swap

func (b *Bool) Swap(new bool) bool

Swap sets the given value and returns the previous value.

func (*Bool) Toggle

func (b *Bool) Toggle() bool

Toggle atomically negates the Boolean and returns the previous value.

Jump to

Keyboard shortcuts

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