utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package utils contains various utility functions that are used by dockerproxy and proxyssh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtSSHLog

func FmtSSHLog(logger Logger, s SSHSessionOrContext, message string, args ...interface{})

FmtSSHLog formats a log message, prefixes it with information about s, and then prints it to Logger.

This message behaves like log.Printf except that it takes a Logger and SSHSessionOrContext as arguments.

Types

type Logger

type Logger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger represents an object that can be used for log messages. It is assumed to be goroutine-safe.

The log.Logger type of the builtin log package implements this type.

type NetworkAddress

type NetworkAddress struct {
	Hostname string
	Port     Port
}

NetworkAddress is a network address consisting of a hostname and a port

func MustParseNetworkAddress

func MustParseNetworkAddress(s string) NetworkAddress

MustParseNetworkAddress is like ParseNetworkAddress except that it calls panic() instead of returning an error.

This function is intended to be used for test cases.

func ParseNetworkAddress

func ParseNetworkAddress(s string) (p NetworkAddress, err error)

ParseNetworkAddress parses a network address of the form 'Hostname:Port'. See function net.Dial, in particular the hostport for allowed combinations.

When parsing fails a non-nil error is returned. Otherwise, error is nil.

func (NetworkAddress) String

func (p NetworkAddress) String() string

String turns this NetworkAddress into a string of the form "host:port". This string is guaranteed to be parsable by ParseNetworkAddress() as well as "net".Dial and friends.

type NetworkAddressListVar

type NetworkAddressListVar []NetworkAddress

NetworkAddressListVar represents a "flag".Value that contains a list of network addresses. It can be passed multiple times, and collects all NetworkAddress in an ordered list.

func (*NetworkAddressListVar) Set

func (p *NetworkAddressListVar) Set(value string) (err error)

Set sets the value of this NetworkAddressListVar This function is intedned to be called by flag.Var()

func (*NetworkAddressListVar) String

func (p *NetworkAddressListVar) String() string

String turns this NetworkAddressListVar into a comma-seperated list of network addresses.

type OneTime

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

OneTime is an object that can be locked exactly once.

The zero value is ready to use. A OneTime must not be copied after creation.

The use-case for this object is an alternative to the sync.Once object. sync.Once has two important downsides. First any call to .Do() does not return before the action has been performed. Second it requires a closure to be passed, resulting in additional code complexity. OneTime works around both of these by providing a single Lock() function that returns a boolean.

 type whatever struct { lock OneTime }
 func (w *whatever) DoSomethingOnlyOnce() {
		if !w.lock.Lock() { // if the action has been started elsewhere, return immediatly.
			return
		}
		// ... action to perform ...
	}

func (*OneTime) Lock

func (ol *OneTime) Lock() bool

Lock attempts to aquire this lock and returns if it was successfull.

Only the first call to this method will return true, all subsequent calls will return false.

type Port

type Port uint16

Port represents the Port of a NetworkAddress

type SSHSessionOrContext

type SSHSessionOrContext interface {
	User() string
	RemoteAddr() net.Addr
}

SSHSessionOrContext represents either an ssh.Session or an ssh.Context. It is used in utility functions that are applicable to both.

See also the github.com/gliderlabs/ssh.

Jump to

Keyboard shortcuts

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