util

package
v0.0.0-...-dd72184 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectPublicNetworkParams

func DetectPublicNetworkParams(publicIPs *[]net.IP, internalIPs []net.IP, netDev *string) error

DetectPublicNetworkParams tries to be smart and find a public IP address and network interface for the local host.

If *publicIPs is nil, attempts to resolve the local hostname and look for non-local addresses. If none are found, figures out the IP from the network interface, if given, or finds the first non-loopback interface.

If *netDev is an empty string, tries to figure out the network device to use from either internalIPs or *publicIPs, whichever is not nil. The netDev pointer itself can be nil, in which case no network device detection is attempted.

func IPFlag

func IPFlag(name, help string) *net.IP

func IPListFlag

func IPListFlag(name, help string) *[]net.IP

func RunCron

func RunCron(ctx context.Context, d time.Duration, fn func(context.Context))

RunCron invokes fn periodically, until the context is canceled. It is a simple wrapper for time.Ticker, but fn is also called immediately as soon as the timer starts.

func WriteFileIfChanged

func WriteFileIfChanged(path string, data []byte) (bool, error)

WriteFileIfChanged updates the contents of a file if they have changed. It returns false if the file already exists and its contents are equal to 'data', true in any other case.

Types

type ConnCache

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

ConnCache caches GRPC connections for a set of (identical) backends, all sharing a common set of options.

func NewConnCache

func NewConnCache(opts ...grpc.DialOption) *ConnCache

NewConnCache returns a new GRPC connection cache with the specified options.

func (*ConnCache) Drop

func (c *ConnCache) Drop(addr string, conn *grpc.ClientConn)

Drop notifies the cache of an error with the connection, which will be (potentially) closed and dropped from the cache.

func (*ConnCache) Get

func (c *ConnCache) Get(ctx context.Context, addr string) (*grpc.ClientConn, error)

Get returns a (potentially cached) GRPC connection.

Jump to

Keyboard shortcuts

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