util

package
v0.0.0-...-129a086 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Address

func Address(network, host string) string

Address constructs a URL from the given network and hostname.

func CallWithContext

func CallWithContext(ctx context.Context, fn func() error) error

func CopyMatchingTag

func CopyMatchingTag(from interface{}, to interface{}, tag string, shouldCopy func(value string) bool)

CopyMatchingTag copies fields tagged tag:"value" from "from" struct onto "to" struct.

func EqualStrings

func EqualStrings(a, b []string) bool

func FillNil

func FillNil(data interface{})

func FillNilExceptDeprecated

func FillNilExceptDeprecated(data interface{})

func FillNilSlices

func FillNilSlices(data interface{}) error

FillNilSlices sets default value on slices that are still nil.

func NiceDurationString

func NiceDurationString(d time.Duration) string

func SetDefaults

func SetDefaults(data interface{})

SetDefaults sets default values on a struct, based on the default annotation.

func UniqueTrimmedStrings

func UniqueTrimmedStrings(ss []string) []string

UniqueTrimmedStrings returns a list of all unique strings in ss, in the order in which they first appear in ss, after trimming away leading and trailing spaces.

Types

type MultiSemaphore

type MultiSemaphore []*Semaphore

MultiSemaphore combines semaphores, making sure to always take and give in the same order (reversed for give). A semaphore may be nil, in which case it is skipped.

func (MultiSemaphore) Give

func (s MultiSemaphore) Give(size int)

func (MultiSemaphore) Take

func (s MultiSemaphore) Take(size int)

func (MultiSemaphore) TakeWithContext

func (s MultiSemaphore) TakeWithContext(ctx context.Context, size int) error

type Semaphore

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

func NewSemaphore

func NewSemaphore(max int) *Semaphore

func (*Semaphore) Available

func (s *Semaphore) Available() int

func (*Semaphore) Give

func (s *Semaphore) Give(size int)

func (*Semaphore) SetCapacity

func (s *Semaphore) SetCapacity(capacity int)

func (*Semaphore) Take

func (s *Semaphore) Take(size int)

func (*Semaphore) TakeWithContext

func (s *Semaphore) TakeWithContext(ctx context.Context, size int) error

Jump to

Keyboard shortcuts

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