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 ¶
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 ...
}
type SSHSessionOrContext ¶
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.