Code clean up
This commit is contained in:
@@ -33,7 +33,7 @@ const (
|
||||
// Errors
|
||||
var (
|
||||
ErrCommandRunUndefinedCommand = errors.New(
|
||||
"Undefined Command")
|
||||
"undefined Command")
|
||||
)
|
||||
|
||||
// Command represents a command handler machine builder
|
||||
|
||||
@@ -31,13 +31,13 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrHandlerUnknownHeaderType = errors.New(
|
||||
"Unknown command header type")
|
||||
"unknown command header type")
|
||||
|
||||
ErrHandlerControlMessageTooLong = errors.New(
|
||||
"Control message was too long")
|
||||
"control message was too long")
|
||||
|
||||
ErrHandlerInvalidControlMessage = errors.New(
|
||||
"Invalid control message")
|
||||
"invalid control message")
|
||||
)
|
||||
|
||||
// HandlerCancelSignal signals the cancel of the entire handling proccess
|
||||
@@ -113,11 +113,6 @@ type streamHandlerSender struct {
|
||||
sendDelay time.Duration
|
||||
}
|
||||
|
||||
// signal sends handler signal
|
||||
func (h streamHandlerSender) signal(hd Header, d []byte, buf []byte) error {
|
||||
return h.handlerSender.signal(hd, d, buf)
|
||||
}
|
||||
|
||||
// Write sends data
|
||||
func (h streamHandlerSender) Write(b []byte) (int, error) {
|
||||
defer time.Sleep(h.sendDelay)
|
||||
|
||||
@@ -28,16 +28,16 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrStreamsInvalidStreamID = errors.New(
|
||||
"Stream ID is invalid")
|
||||
"stream ID is invalid")
|
||||
|
||||
ErrStreamsStreamOperateInactiveStream = errors.New(
|
||||
"Specified stream was inactive for operation")
|
||||
"specified stream was inactive for operation")
|
||||
|
||||
ErrStreamsStreamClosingInactiveStream = errors.New(
|
||||
"Closing an inactive stream is not allowed")
|
||||
"closing an inactive stream is not allowed")
|
||||
|
||||
ErrStreamsStreamReleasingInactiveStream = errors.New(
|
||||
"Releasing an inactive stream is not allowed")
|
||||
"releasing an inactive stream is not allowed")
|
||||
)
|
||||
|
||||
// StreamError Stream Error signal
|
||||
|
||||
@@ -28,22 +28,22 @@ import (
|
||||
//Errors
|
||||
var (
|
||||
ErrAddressParseBufferTooSmallForHeader = errors.New(
|
||||
"Buffer space was too small to parse the address header")
|
||||
"buffer space was too small to parse the address header")
|
||||
|
||||
ErrAddressParseBufferTooSmallForIPv4 = errors.New(
|
||||
"Buffer space was too small to parse the IPv4 address")
|
||||
"buffer space was too small to parse the IPv4 address")
|
||||
|
||||
ErrAddressParseBufferTooSmallForIPv6 = errors.New(
|
||||
"Buffer space was too small to parse the IPv6 address")
|
||||
"buffer space was too small to parse the IPv6 address")
|
||||
|
||||
ErrAddressParseBufferTooSmallForHostName = errors.New(
|
||||
"Buffer space was too small to parse the hostname address")
|
||||
"buffer space was too small to parse the hostname address")
|
||||
|
||||
ErrAddressMarshalBufferTooSmall = errors.New(
|
||||
"Buffer space was too small to marshal the address")
|
||||
"buffer space was too small to marshal the address")
|
||||
|
||||
ErrAddressInvalidAddressType = errors.New(
|
||||
"Invalid address type")
|
||||
"invalid address type")
|
||||
)
|
||||
|
||||
// AddressType Type of the address
|
||||
|
||||
@@ -26,10 +26,10 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrIntegerMarshalNotEnoughBuffer = errors.New(
|
||||
"Not enough buffer to marshal the integer")
|
||||
"not enough buffer to marshal the integer")
|
||||
|
||||
ErrIntegerMarshalTooLarge = errors.New(
|
||||
"Integer cannot be marshalled, because the vaule was too large")
|
||||
"integer cannot be marshalled, because the vaule was too large")
|
||||
)
|
||||
|
||||
// Integer is a 16bit unsigned integer data
|
||||
|
||||
@@ -74,34 +74,34 @@ type sshAuthMethodBuilder func(b []byte) []ssh.AuthMethod
|
||||
// Errors
|
||||
var (
|
||||
ErrSSHAuthCancelled = errors.New(
|
||||
"Authentication has been cancelled")
|
||||
"authentication has been cancelled")
|
||||
|
||||
ErrSSHInvalidAuthMethod = errors.New(
|
||||
"Invalid auth method")
|
||||
"invalid auth method")
|
||||
|
||||
ErrSSHInvalidAddress = errors.New(
|
||||
"Invalid address")
|
||||
"invalid address")
|
||||
|
||||
ErrSSHRemoteFingerprintVerificationCancelled = errors.New(
|
||||
"Server Fingerprint verification process has been cancelled")
|
||||
"server Fingerprint verification process has been cancelled")
|
||||
|
||||
ErrSSHRemoteFingerprintRefused = errors.New(
|
||||
"Server Fingerprint has been refused")
|
||||
"server Fingerprint has been refused")
|
||||
|
||||
ErrSSHRemoteConnUnavailable = errors.New(
|
||||
"Remote SSH connection is unavailable")
|
||||
"remote SSH connection is unavailable")
|
||||
|
||||
ErrSSHUnexpectedFingerprintVerificationRespond = errors.New(
|
||||
"Unexpected fingerprint verification respond")
|
||||
"unexpected fingerprint verification respond")
|
||||
|
||||
ErrSSHUnexpectedCredentialDataRespond = errors.New(
|
||||
"Unexpected credential data respond")
|
||||
"unexpected credential data respond")
|
||||
|
||||
ErrSSHCredentialDataTooLarge = errors.New(
|
||||
"Credential was too large")
|
||||
"credential was too large")
|
||||
|
||||
ErrSSHUnknownClientSignal = errors.New(
|
||||
"Unknown client signal")
|
||||
"unknown client signal")
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -26,10 +26,10 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrStringParseBufferTooSmall = errors.New(
|
||||
"Not enough buffer space to parse given string")
|
||||
"not enough buffer space to parse given string")
|
||||
|
||||
ErrStringMarshalBufferTooSmall = errors.New(
|
||||
"Not enough buffer space to marshal given string")
|
||||
"not enough buffer space to marshal given string")
|
||||
)
|
||||
|
||||
// String data
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrTelnetUnableToReceiveRemoteConn = errors.New(
|
||||
"Unable to acquire remote connection handle")
|
||||
"unable to acquire remote connection handle")
|
||||
)
|
||||
|
||||
// Error codes
|
||||
|
||||
@@ -108,7 +108,7 @@ func (s Server) IsTLS() bool {
|
||||
// Verify verifies current configuration
|
||||
func (s Server) Verify() error {
|
||||
if net.ParseIP(s.ListenInterface) == nil {
|
||||
return fmt.Errorf("Invalid IP address \"%s\"", s.ListenInterface)
|
||||
return fmt.Errorf("invalid IP address \"%s\"", s.ListenInterface)
|
||||
}
|
||||
|
||||
if (len(s.TLSCertificateFile) > 0 && len(s.TLSCertificateKeyFile) <= 0) ||
|
||||
@@ -132,7 +132,7 @@ func (m Meta) Concretize() (map[string]string, error) {
|
||||
result, err := v.Parse()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse Meta \"%s\": %s", k, err)
|
||||
return nil, fmt.Errorf("unable to parse Meta \"%s\": %s", k, err)
|
||||
}
|
||||
|
||||
mm[k] = result
|
||||
@@ -175,7 +175,7 @@ type Common struct {
|
||||
// Verify verifies current setting
|
||||
func (c Configuration) Verify() error {
|
||||
if len(c.Servers) <= 0 {
|
||||
return errors.New("Must specify at least one server")
|
||||
return errors.New("must specify at least one server")
|
||||
}
|
||||
|
||||
for i, c := range c.Servers {
|
||||
@@ -185,7 +185,7 @@ func (c Configuration) Verify() error {
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("Invalid setting for server %d: %s", i, vErr)
|
||||
return fmt.Errorf("invalid setting for server %d: %s", i, vErr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -42,16 +42,6 @@ func parseEnv(name string) string {
|
||||
return os.Getenv(v[21:])
|
||||
}
|
||||
|
||||
func parseEnvDef(name string, def string) string {
|
||||
v := parseEnv(name)
|
||||
|
||||
if len(v) > 0 {
|
||||
return v
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// Enviro creates an environment variable based configuration loader
|
||||
func Enviro() Loader {
|
||||
return func(log log.Logger) (string, Configuration, error) {
|
||||
@@ -75,7 +65,7 @@ func Enviro() Loader {
|
||||
|
||||
if cfgErr != nil {
|
||||
return enviroTypeName, Configuration{}, fmt.Errorf(
|
||||
"Failed to build the configuration: %s", cfgErr)
|
||||
"failed to build the configuration: %s", cfgErr)
|
||||
}
|
||||
|
||||
listenIface := parseEnv("SSHWIFTY_LISTENINTERFACE")
|
||||
@@ -122,7 +112,7 @@ func Enviro() Loader {
|
||||
|
||||
if jErr != nil {
|
||||
return enviroTypeName, Configuration{}, fmt.Errorf(
|
||||
"Invalid \"SSHWIFTY_PRESETS\": %s", jErr)
|
||||
"invalid \"SSHWIFTY_PRESETS\": %s", jErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +120,7 @@ func Enviro() Loader {
|
||||
|
||||
if err != nil {
|
||||
return enviroTypeName, Configuration{}, fmt.Errorf(
|
||||
"Unable to parse Preset data: %s", err)
|
||||
"unable to parse Preset data: %s", err)
|
||||
}
|
||||
|
||||
return enviroTypeName, Configuration{
|
||||
|
||||
@@ -106,7 +106,7 @@ func (f fileCfgPresets) concretize() ([]Preset, error) {
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"Unable to concretize Preset %d (titled \"%s\"): %s",
|
||||
"unable to concretize Preset %d (titled \"%s\"): %s",
|
||||
i+1, p.Title, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,6 @@ func Redundant(loaders ...Loader) Loader {
|
||||
}
|
||||
|
||||
return redundantTypeName, Configuration{}, fmt.Errorf(
|
||||
"All existing redundant loader has failed")
|
||||
"all existing redundant loader has failed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (s String) Parse() (string, error) {
|
||||
f, e := os.Open(fPath)
|
||||
|
||||
if e != nil {
|
||||
return "", fmt.Errorf("Unable to open %s: %s", fPath, e)
|
||||
return "", fmt.Errorf("unable to open %s: %s", fPath, e)
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
@@ -59,7 +59,7 @@ func (s String) Parse() (string, error) {
|
||||
fData, e := ioutil.ReadAll(f)
|
||||
|
||||
if e != nil {
|
||||
return "", fmt.Errorf("Unable to read from %s: %s", fPath, e)
|
||||
return "", fmt.Errorf("unable to read from %s: %s", fPath, e)
|
||||
}
|
||||
|
||||
return string(fData), nil
|
||||
@@ -74,6 +74,6 @@ func (s String) Parse() (string, error) {
|
||||
|
||||
default:
|
||||
return "", fmt.Errorf(
|
||||
"Scheme \"%s\" was unsupported", ss[:sSchemeLeadIdx])
|
||||
"scheme \"%s\" was unsupported", ss[:sSchemeLeadIdx])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func TestStringFile(t *testing.T) {
|
||||
|
||||
ss = String("file://" + filePath + ".notexist")
|
||||
|
||||
result, err = ss.Parse()
|
||||
_, err = ss.Parse()
|
||||
|
||||
if err == nil {
|
||||
t.Error("Parsing an non-existing file should result an error")
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrAccessControlDialTargetHostNotAllowed = errors.New(
|
||||
"Unable to dial to the specified remote host due to restriction")
|
||||
"unable to dial to the specified remote host due to restriction")
|
||||
)
|
||||
|
||||
// AllowedHosts contains a map of allowed remote hosts
|
||||
|
||||
@@ -22,7 +22,7 @@ import "errors"
|
||||
// Errors
|
||||
var (
|
||||
ErrFetchReaderNotEnoughBuffer = errors.New(
|
||||
"Not enough buffer")
|
||||
"not enough buffer")
|
||||
)
|
||||
|
||||
// FetchReaderFetcher generates data for SourceReader
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// Errors
|
||||
var (
|
||||
ErrReadUntilCompletedBufferFull = errors.New(
|
||||
"Cannot read more, not enough data buffer")
|
||||
"cannot read more, not enough data buffer")
|
||||
)
|
||||
|
||||
// LimitedReader reads only n bytes of data
|
||||
|
||||
@@ -24,10 +24,6 @@ import (
|
||||
"github.com/nirui/sshwifty/application/network"
|
||||
)
|
||||
|
||||
var (
|
||||
emptyTime = time.Time{}
|
||||
)
|
||||
|
||||
type listener struct {
|
||||
*net.TCPListener
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ func (d dumpWrite) Write(b []byte) (int, error) {
|
||||
// Errors
|
||||
var (
|
||||
ErrInvalidIPAddress = errors.New(
|
||||
"Invalid IP address")
|
||||
"invalid IP address")
|
||||
)
|
||||
|
||||
// HandlerBuilder builds a HTTP handler
|
||||
@@ -60,7 +60,6 @@ type CloseCallback func(error)
|
||||
// Server represents a server
|
||||
type Server struct {
|
||||
logger log.Logger
|
||||
cfg configuration.Common
|
||||
shutdownWait *sync.WaitGroup
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user