From e30ae972f4c76940b4ecf9aa555f2c6a20b093de Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 25 Aug 2018 21:30:25 +0200 Subject: [PATCH] gofmt --- cmd/adaptors.go | 38 ++++++++++++++--------------- cmd/config_connect.go | 8 +++--- cmd/config_job_control.go | 2 +- cmd/config_job_local.go | 4 +-- cmd/config_job_pull.go | 7 +++--- cmd/config_job_source.go | 4 +-- cmd/config_logging.go | 6 ++--- cmd/config_mapfilter.go | 6 ++--- cmd/config_parse.go | 4 +-- cmd/config_serve_tcp.go | 6 ++--- cmd/config_test.go | 4 +-- cmd/endpoint/endpoint.go | 37 ++++++++++++++-------------- cmd/tlsconf/tlsconf.go | 6 ++--- logger/nulllogger.go | 22 ++++++++--------- replication/context.go | 3 +-- replication/fsrep/fsfsm.go | 19 ++++++--------- replication/internal/queue/queue.go | 10 ++++---- replication/mainfsm.go | 10 +++----- replication/pdu/pdu_extras.go | 16 ++++++------ replication/pdu/pdu_test.go | 8 +++--- replication/policy.go | 1 - util/contextflexibletimeout.go | 12 ++++----- util/contextflexibletimeout_test.go | 30 +++++++++++------------ util/io.go | 2 +- zfs/diff.go | 4 +-- zfs/mapping.go | 6 ++--- zfs/versions.go | 2 +- 27 files changed, 130 insertions(+), 147 deletions(-) diff --git a/cmd/adaptors.go b/cmd/adaptors.go index 86e7c37..acf1a0d 100644 --- a/cmd/adaptors.go +++ b/cmd/adaptors.go @@ -9,8 +9,8 @@ import ( "time" "github.com/problame/go-streamrpc" - "github.com/zrepl/zrepl/util" "github.com/zrepl/zrepl/logger" + "github.com/zrepl/zrepl/util" ) type logNetConnConnecter struct { @@ -29,36 +29,35 @@ func (l logNetConnConnecter) Connect(ctx context.Context) (net.Conn, error) { } type logListenerFactory struct { - ListenerFactory - ReadDump, WriteDump string + ListenerFactory + ReadDump, WriteDump string } var _ ListenerFactory = logListenerFactory{} type logListener struct { - net.Listener - ReadDump, WriteDump string + net.Listener + ReadDump, WriteDump string } var _ net.Listener = logListener{} func (m logListenerFactory) Listen() (net.Listener, error) { - l, err := m.ListenerFactory.Listen() - if err != nil { - return nil, err - } - return logListener{l, m.ReadDump, m.WriteDump}, nil + l, err := m.ListenerFactory.Listen() + if err != nil { + return nil, err + } + return logListener{l, m.ReadDump, m.WriteDump}, nil } func (l logListener) Accept() (net.Conn, error) { - conn, err := l.Listener.Accept() - if err != nil { - return nil, err - } - return util.NewNetConnLogger(conn, l.ReadDump, l.WriteDump) + conn, err := l.Listener.Accept() + if err != nil { + return nil, err + } + return util.NewNetConnLogger(conn, l.ReadDump, l.WriteDump) } - type netsshAddr struct{} func (netsshAddr) Network() string { return "netssh" } @@ -78,7 +77,7 @@ func (netsshConnToNetConnAdatper) SetReadDeadline(t time.Time) error { return ni func (netsshConnToNetConnAdatper) SetWriteDeadline(t time.Time) error { return nil } -type streamrpcLogAdaptor = twoClassLogAdaptor +type streamrpcLogAdaptor = twoClassLogAdaptor type replicationLogAdaptor = twoClassLogAdaptor type twoClassLogAdaptor struct { @@ -87,7 +86,7 @@ type twoClassLogAdaptor struct { var _ streamrpc.Logger = twoClassLogAdaptor{} -func (a twoClassLogAdaptor) Errorf(fmtStr string, args... interface{}) { +func (a twoClassLogAdaptor) Errorf(fmtStr string, args ...interface{}) { const errorSuffix = ": %s" if len(args) == 1 { if err, ok := args[0].(error); ok && strings.HasSuffix(fmtStr, errorSuffix) { @@ -99,7 +98,6 @@ func (a twoClassLogAdaptor) Errorf(fmtStr string, args... interface{}) { a.Logger.Error(fmt.Sprintf(fmtStr, args...)) } -func (a twoClassLogAdaptor) Infof(fmtStr string, args... interface{}) { +func (a twoClassLogAdaptor) Infof(fmtStr string, args ...interface{}) { a.Logger.Info(fmt.Sprintf(fmtStr, args...)) } - diff --git a/cmd/config_connect.go b/cmd/config_connect.go index 83c7976..e13274a 100644 --- a/cmd/config_connect.go +++ b/cmd/config_connect.go @@ -11,8 +11,8 @@ import ( "github.com/pkg/errors" "github.com/problame/go-netssh" "github.com/problame/go-streamrpc" - "time" "github.com/zrepl/zrepl/cmd/tlsconf" + "time" ) type SSHStdinserverConnecter struct { @@ -51,12 +51,12 @@ func parseSSHStdinserverConnecter(i map[string]interface{}) (c *SSHStdinserverCo } -type netsshConnToConn struct { *netssh.SSHConn } +type netsshConnToConn struct{ *netssh.SSHConn } var _ net.Conn = netsshConnToConn{} -func (netsshConnToConn) SetDeadline(dl time.Time) error { return nil } -func (netsshConnToConn) SetReadDeadline(dl time.Time) error { return nil } +func (netsshConnToConn) SetDeadline(dl time.Time) error { return nil } +func (netsshConnToConn) SetReadDeadline(dl time.Time) error { return nil } func (netsshConnToConn) SetWriteDeadline(dl time.Time) error { return nil } func (c *SSHStdinserverConnecter) Connect(dialCtx context.Context) (net.Conn, error) { diff --git a/cmd/config_job_control.go b/cmd/config_job_control.go index 300e4b0..85d906e 100644 --- a/cmd/config_job_control.go +++ b/cmd/config_job_control.go @@ -5,10 +5,10 @@ import ( "context" "encoding/json" "github.com/pkg/errors" + "github.com/zrepl/zrepl/logger" "io" "net" "net/http" - "github.com/zrepl/zrepl/logger" ) type ControlJob struct { diff --git a/cmd/config_job_local.go b/cmd/config_job_local.go index fafac4d..fce3708 100644 --- a/cmd/config_job_local.go +++ b/cmd/config_job_local.go @@ -6,10 +6,10 @@ import ( "context" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" + "github.com/zrepl/zrepl/cmd/endpoint" + "github.com/zrepl/zrepl/replication" "github.com/zrepl/zrepl/zfs" "sync" - "github.com/zrepl/zrepl/replication" - "github.com/zrepl/zrepl/cmd/endpoint" ) type LocalJob struct { diff --git a/cmd/config_job_pull.go b/cmd/config_job_pull.go index bec1196..df6dab1 100644 --- a/cmd/config_job_pull.go +++ b/cmd/config_job_pull.go @@ -11,8 +11,8 @@ import ( "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/problame/go-streamrpc" - "github.com/zrepl/zrepl/replication" "github.com/zrepl/zrepl/cmd/endpoint" + "github.com/zrepl/zrepl/replication" ) type PullJob struct { @@ -28,7 +28,7 @@ type PullJob struct { Debug JobDebugSettings task *Task - rep *replication.Replication + rep *replication.Replication } func parsePullJob(c JobParsingContext, name string, i map[string]interface{}) (j *PullJob, err error) { @@ -155,7 +155,6 @@ var STREAMRPC_CONFIG = &streamrpc.ConnConfig{ // FIXME oversight and configurabi }, } - func (j *PullJob) doRun(ctx context.Context) { j.task.Enter("run") @@ -184,7 +183,7 @@ func (j *PullJob) doRun(ctx context.Context) { } ctx = replication.WithLogger(ctx, replicationLogAdaptor{j.task.Log().WithField("subsystem", "replication")}) - ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{j.task.Log().WithField("subsystem", "rpc.protocol")}) + ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{j.task.Log().WithField("subsystem", "rpc.protocol")}) ctx = endpoint.WithLogger(ctx, j.task.Log().WithField("subsystem", "rpc.endpoint")) j.rep = replication.NewReplication() diff --git a/cmd/config_job_source.go b/cmd/config_job_source.go index eaa9457..c79d3c9 100644 --- a/cmd/config_job_source.go +++ b/cmd/config_job_source.go @@ -7,8 +7,8 @@ import ( "github.com/mitchellh/mapstructure" "github.com/pkg/errors" "github.com/problame/go-streamrpc" - "net" "github.com/zrepl/zrepl/cmd/endpoint" + "net" ) type SourceJob struct { @@ -160,7 +160,7 @@ func (j *SourceJob) serve(ctx context.Context, task *Task) { connChan := make(chan connChanMsg) // Serve connections until interrupted or error - outer: +outer: for { go func() { diff --git a/cmd/config_logging.go b/cmd/config_logging.go index 00707ee..200f365 100644 --- a/cmd/config_logging.go +++ b/cmd/config_logging.go @@ -1,15 +1,15 @@ package cmd import ( + "crypto/tls" + "crypto/x509" "github.com/mattn/go-isatty" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" + "github.com/zrepl/zrepl/cmd/tlsconf" "github.com/zrepl/zrepl/logger" "os" "time" - "crypto/tls" - "crypto/x509" - "github.com/zrepl/zrepl/cmd/tlsconf" ) type LoggingConfig struct { diff --git a/cmd/config_mapfilter.go b/cmd/config_mapfilter.go index e59f482..0a1de54 100644 --- a/cmd/config_mapfilter.go +++ b/cmd/config_mapfilter.go @@ -6,8 +6,8 @@ import ( "github.com/mitchellh/mapstructure" "github.com/pkg/errors" - "github.com/zrepl/zrepl/zfs" "github.com/zrepl/zrepl/cmd/endpoint" + "github.com/zrepl/zrepl/zfs" ) type DatasetMapFilter struct { @@ -210,8 +210,8 @@ func (m DatasetMapFilter) Invert() (endpoint.FSMap, error) { } inv.entries[0] = datasetMapFilterEntry{ - path: mp, - mapping: e.path.ToString(), + path: mp, + mapping: e.path.ToString(), subtreeMatch: e.subtreeMatch, } diff --git a/cmd/config_parse.go b/cmd/config_parse.go index 9c334ae..573436a 100644 --- a/cmd/config_parse.go +++ b/cmd/config_parse.go @@ -7,12 +7,12 @@ import ( yaml "github.com/go-yaml/yaml" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" + "github.com/problame/go-streamrpc" + "github.com/zrepl/zrepl/replication" "os" "regexp" "strconv" "time" - "github.com/zrepl/zrepl/replication" - "github.com/problame/go-streamrpc" ) var ConfigFileDefaultLocations []string = []string{ diff --git a/cmd/config_serve_tcp.go b/cmd/config_serve_tcp.go index b85d01a..bfc4c49 100644 --- a/cmd/config_serve_tcp.go +++ b/cmd/config_serve_tcp.go @@ -22,8 +22,8 @@ type TCPListenerFactory struct { func parseTCPListenerFactory(c JobParsingContext, i map[string]interface{}) (*TCPListenerFactory, error) { var in struct { - Address string - TLS map[string]interface{} + Address string + TLS map[string]interface{} } if err := mapstructure.Decode(i, &in); err != nil { return nil, errors.Wrap(err, "mapstructure error") @@ -56,7 +56,7 @@ func parseTCPListenerFactory(c JobParsingContext, i map[string]interface{}) (*TC lf.clientCA, err = tlsconf.ParseCAFile(in.CA) if err != nil { - return errors.Wrap(err,"cannot parse ca file") + return errors.Wrap(err, "cannot parse ca file") } lf.serverCert, err = tls.LoadX509KeyPair(in.Cert, in.Key) diff --git a/cmd/config_test.go b/cmd/config_test.go index 253e9fc..f53453a 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -136,7 +136,7 @@ func TestDatasetMapFilter(t *testing.T) { expectMapping(map1, "q/r", "root4/1/2/r") map2 := map[string]string{ // identity mapping - "<":"", + "<": "", } expectMapping(map2, "foo/bar", "foo/bar") @@ -280,4 +280,4 @@ func TestDatasetMapFilter_Invert(t *testing.T) { expectMapping(inv, "foo/bar", "", false, true) expectMapping(inv, "foo/bar/bee", "bee", false, false) -} \ No newline at end of file +} diff --git a/cmd/endpoint/endpoint.go b/cmd/endpoint/endpoint.go index 927cdd6..bd03a6a 100644 --- a/cmd/endpoint/endpoint.go +++ b/cmd/endpoint/endpoint.go @@ -2,20 +2,20 @@ package endpoint import ( - "github.com/zrepl/zrepl/replication/pdu" - "github.com/problame/go-streamrpc" - "github.com/zrepl/zrepl/zfs" - "io" - "github.com/pkg/errors" - "github.com/golang/protobuf/proto" "bytes" "context" + "github.com/golang/protobuf/proto" + "github.com/pkg/errors" + "github.com/problame/go-streamrpc" "github.com/zrepl/zrepl/replication" + "github.com/zrepl/zrepl/replication/pdu" + "github.com/zrepl/zrepl/zfs" + "io" ) // Sender implements replication.ReplicationEndpoint for a sending side type Sender struct { - FSFilter zfs.DatasetFilter + FSFilter zfs.DatasetFilter FilesystemVersionFilter zfs.FilesystemVersionFilter } @@ -87,16 +87,16 @@ type FSFilter interface { // FIXME: can we get away without error types here? type FSMap interface { FSFilter - Map(path *zfs.DatasetPath) (*zfs.DatasetPath,error) - Invert() (FSMap,error) - AsFilter() (FSFilter) + Map(path *zfs.DatasetPath) (*zfs.DatasetPath, error) + Invert() (FSMap, error) + AsFilter() FSFilter } // Receiver implements replication.ReplicationEndpoint for a receiving side type Receiver struct { fsmapInv FSMap - fsmap FSMap - fsvf zfs.FilesystemVersionFilter + fsmap FSMap + fsvf zfs.FilesystemVersionFilter } func NewReceiver(fsmap FSMap, fsvf zfs.FilesystemVersionFilter) (*Receiver, error) { @@ -219,12 +219,11 @@ func (e *Receiver) Receive(ctx context.Context, req *pdu.ReceiveReq, sendStream // RPC STUBS // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - const ( - RPCListFilesystems = "ListFilesystems" + RPCListFilesystems = "ListFilesystems" RPCListFilesystemVersions = "ListFilesystemVersions" - RPCReceive = "Receive" - RPCSend = "Send" + RPCReceive = "Receive" + RPCSend = "Send" ) // Remote implements an endpoint stub that uses streamrpc as a transport. @@ -295,13 +294,13 @@ func (s Remote) Send(ctx context.Context, r *pdu.SendReq) (*pdu.SendRes, io.Read var res pdu.SendRes if err := proto.Unmarshal(rb.Bytes(), &res); err != nil { rs.Close() - return nil, nil, err + return nil, nil, err } // FIXME make sure the consumer will read the reader until the end... return &res, rs, nil } -func (s Remote) Receive(ctx context.Context, r *pdu.ReceiveReq, sendStream io.ReadCloser) (error) { +func (s Remote) Receive(ctx context.Context, r *pdu.ReceiveReq, sendStream io.ReadCloser) error { defer sendStream.Close() b, err := proto.Marshal(r) if err != nil { @@ -414,6 +413,6 @@ func (a *Handler) Handle(ctx context.Context, endpoint string, reqStructured *by return bytes.NewBuffer(b), nil, err } - Err: +Err: return nil, nil, errors.New("no handler for given endpoint") } diff --git a/cmd/tlsconf/tlsconf.go b/cmd/tlsconf/tlsconf.go index 77372f8..cf47968 100644 --- a/cmd/tlsconf/tlsconf.go +++ b/cmd/tlsconf/tlsconf.go @@ -43,7 +43,7 @@ func NewClientAuthListener( } tlsConf := tls.Config{ - Certificates: []tls.Certificate{serverCert}, + Certificates: []tls.Certificate{serverCert}, ClientCAs: ca, ClientAuth: tls.RequireAndVerifyClientCert, PreferServerCipherSuites: true, @@ -114,8 +114,8 @@ func ClientAuthClient(serverName string, rootCA *x509.CertPool, clientCert tls.C tlsConfig := &tls.Config{ Certificates: []tls.Certificate{clientCert}, RootCAs: rootCA, - ServerName: serverName, + ServerName: serverName, } tlsConfig.BuildNameToCertificate() return tlsConfig, nil -} \ No newline at end of file +} diff --git a/logger/nulllogger.go b/logger/nulllogger.go index 3233dfe..ec954f7 100644 --- a/logger/nulllogger.go +++ b/logger/nulllogger.go @@ -1,7 +1,6 @@ package logger - -type nullLogger struct {} +type nullLogger struct{} var _ Logger = nullLogger{} @@ -9,14 +8,13 @@ func NewNullLogger() Logger { return nullLogger{} } -func (n nullLogger) WithOutlet(outlet Outlet, level Level) Logger { return n } +func (n nullLogger) WithOutlet(outlet Outlet, level Level) Logger { return n } func (n nullLogger) ReplaceField(field string, val interface{}) Logger { return n } -func (n nullLogger) WithField(field string, val interface{}) Logger { return n } -func (n nullLogger) WithFields(fields Fields) Logger { return n } -func (n nullLogger) WithError(err error) Logger { return n } -func (nullLogger) Debug(msg string) {} -func (nullLogger) Info(msg string) {} -func (nullLogger) Warn(msg string) {} -func (nullLogger) Error(msg string) {} -func (nullLogger) Printf(format string, args ...interface{}) {} - +func (n nullLogger) WithField(field string, val interface{}) Logger { return n } +func (n nullLogger) WithFields(fields Fields) Logger { return n } +func (n nullLogger) WithError(err error) Logger { return n } +func (nullLogger) Debug(msg string) {} +func (nullLogger) Info(msg string) {} +func (nullLogger) Warn(msg string) {} +func (nullLogger) Error(msg string) {} +func (nullLogger) Printf(format string, args ...interface{}) {} diff --git a/replication/context.go b/replication/context.go index 7b4b0e9..7e43981 100644 --- a/replication/context.go +++ b/replication/context.go @@ -1,8 +1,8 @@ package replication import ( - "github.com/zrepl/zrepl/logger" "context" + "github.com/zrepl/zrepl/logger" "github.com/zrepl/zrepl/replication/fsrep" ) @@ -27,4 +27,3 @@ func getLogger(ctx context.Context) Logger { } return l } - diff --git a/replication/fsrep/fsfsm.go b/replication/fsrep/fsfsm.go index d07fd3d..d542456 100644 --- a/replication/fsrep/fsfsm.go +++ b/replication/fsrep/fsfsm.go @@ -12,8 +12,8 @@ import ( "sync" "time" - "github.com/zrepl/zrepl/replication/pdu" "github.com/zrepl/zrepl/logger" + "github.com/zrepl/zrepl/replication/pdu" ) type contextKey int @@ -51,18 +51,17 @@ type StepReport struct { } type Report struct { - Filesystem string - Status string - Problem string - Completed,Pending []*StepReport + Filesystem string + Status string + Problem string + Completed, Pending []*StepReport } - //go:generate stringer -type=State type State uint const ( - Ready State = 1 << iota + Ready State = 1 << iota RetryWait PermanentError Completed @@ -123,7 +122,7 @@ func (b *ReplicationBuilder) Done() (r *Replication) { } else { b.r.state = Completed } - r = b.r + r = b.r b.r = nil return r } @@ -136,12 +135,11 @@ func NewReplicationWithPermanentError(fs string, err error) *Replication { } } - //go:generate stringer -type=StepState type StepState uint const ( - StepReady StepState = 1 << iota + StepReady StepState = 1 << iota StepRetry StepPermanentError StepCompleted @@ -387,4 +385,3 @@ func (step *ReplicationStep) Report() *StepReport { } return &rep } - diff --git a/replication/internal/queue/queue.go b/replication/internal/queue/queue.go index a187026..a3d7c0c 100644 --- a/replication/internal/queue/queue.go +++ b/replication/internal/queue/queue.go @@ -1,8 +1,8 @@ package queue import ( - "time" "sort" + "time" . "github.com/zrepl/zrepl/replication/fsrep" ) @@ -27,12 +27,12 @@ func NewReplicationQueue() *ReplicationQueue { func (q ReplicationQueue) Len() int { return len(q) } func (q ReplicationQueue) Swap(i, j int) { q[i], q[j] = q[j], q[i] } -type lessmapEntry struct{ +type lessmapEntry struct { prio int - less func(a,b *replicationQueueItem) bool + less func(a, b *replicationQueueItem) bool } -var lessmap = map[State]lessmapEntry { +var lessmap = map[State]lessmapEntry{ Ready: { prio: 0, less: func(a, b *replicationQueueItem) bool { @@ -94,7 +94,7 @@ func (q *ReplicationQueue) GetNext() (done []*Replication, next *ReplicationQueu func (q *ReplicationQueue) Add(fsr *Replication) { *q = append(*q, &replicationQueueItem{ - fsr: fsr, + fsr: fsr, state: fsr.State(), }) } diff --git a/replication/mainfsm.go b/replication/mainfsm.go index ea1308f..f9a0dcb 100644 --- a/replication/mainfsm.go +++ b/replication/mainfsm.go @@ -10,17 +10,17 @@ import ( "sync" "time" - "github.com/zrepl/zrepl/replication/pdu" "github.com/zrepl/zrepl/replication/fsrep" - . "github.com/zrepl/zrepl/replication/internal/queue" . "github.com/zrepl/zrepl/replication/internal/diff" + . "github.com/zrepl/zrepl/replication/internal/queue" + "github.com/zrepl/zrepl/replication/pdu" ) //go:generate stringer -type=State type State uint const ( - Planning State = 1 << iota + Planning State = 1 << iota PlanningError Working WorkingWait @@ -77,7 +77,6 @@ type Report struct { Active *fsrep.Report } - func NewReplication() *Replication { r := Replication{ state: Planning, @@ -101,7 +100,6 @@ type Receiver interface { fsrep.Receiver } - type FilteredError struct{ fs string } func NewFilteredError(fs string) *FilteredError { @@ -110,7 +108,6 @@ func NewFilteredError(fs string) *FilteredError { func (f FilteredError) Error() string { return "endpoint does not allow access to filesystem " + f.fs } - type updater func(func(*Replication)) (newState State) type state func(ctx context.Context, sender Sender, receiver Receiver, u updater) state @@ -381,4 +378,3 @@ func (r *Replication) Report() *Report { return &rep } - diff --git a/replication/pdu/pdu_extras.go b/replication/pdu/pdu_extras.go index 19e27e8..b009d3b 100644 --- a/replication/pdu/pdu_extras.go +++ b/replication/pdu/pdu_extras.go @@ -33,11 +33,11 @@ func FilesystemVersionFromZFS(fsv zfs.FilesystemVersion) *FilesystemVersion { panic("unknown fsv.Type: " + fsv.Type) } return &FilesystemVersion{ - Type: t, - Name: fsv.Name, - Guid: fsv.Guid, + Type: t, + Name: fsv.Name, + Guid: fsv.Guid, CreateTXG: fsv.CreateTXG, - Creation: fsv.Creation.Format(time.RFC3339), + Creation: fsv.Creation.Format(time.RFC3339), } } @@ -64,10 +64,10 @@ func (v *FilesystemVersion) ZFSFilesystemVersion() *zfs.FilesystemVersion { } } return &zfs.FilesystemVersion{ - Type: v.Type.ZFSVersionType(), - Name: v.Name, - Guid: v.Guid, + Type: v.Type.ZFSVersionType(), + Name: v.Name, + Guid: v.Guid, CreateTXG: v.CreateTXG, - Creation: ct, + Creation: ct, } } diff --git a/replication/pdu/pdu_test.go b/replication/pdu/pdu_test.go index 86e2b49..6a1d596 100644 --- a/replication/pdu/pdu_test.go +++ b/replication/pdu/pdu_test.go @@ -1,15 +1,15 @@ package pdu import ( - "testing" "github.com/stretchr/testify/assert" + "testing" ) func TestFilesystemVersion_RelName(t *testing.T) { type TestCase struct { - In FilesystemVersion - Out string + In FilesystemVersion + Out string Panic bool } @@ -56,7 +56,7 @@ func TestFilesystemVersion_ZFSFilesystemVersion(t *testing.T) { emptyZFS := empty.ZFSFilesystemVersion() assert.Zero(t, emptyZFS.Creation) - dateInvalid := &FilesystemVersion{Creation:"foobar"} + dateInvalid := &FilesystemVersion{Creation: "foobar"} assert.Panics(t, func() { dateInvalid.ZFSFilesystemVersion() }) diff --git a/replication/policy.go b/replication/policy.go index ea9b190..83398af 100644 --- a/replication/policy.go +++ b/replication/policy.go @@ -9,4 +9,3 @@ const ( ) const DEFAULT_INITIAL_REPL_POLICY = InitialReplPolicyMostRecent - diff --git a/util/contextflexibletimeout.go b/util/contextflexibletimeout.go index dc84549..422318d 100644 --- a/util/contextflexibletimeout.go +++ b/util/contextflexibletimeout.go @@ -2,18 +2,18 @@ package util import ( "context" - "time" "sync" + "time" ) type contextWithOptionalDeadline struct { context.Context - m sync.Mutex + m sync.Mutex deadline time.Time done chan struct{} - err error + err error } func (c *contextWithOptionalDeadline) Deadline() (deadline time.Time, ok bool) { @@ -28,7 +28,7 @@ func (c *contextWithOptionalDeadline) Err() error { return c.err } -func (c *contextWithOptionalDeadline) Done() (<-chan struct{}) { +func (c *contextWithOptionalDeadline) Done() <-chan struct{} { return c.done } @@ -37,8 +37,8 @@ func ContextWithOptionalDeadline(pctx context.Context) (ctx context.Context, enf // mctx can only be cancelled by cancelMctx, not by a potential cancel of pctx rctx := &contextWithOptionalDeadline{ Context: pctx, - done: make(chan struct{}), - err: nil, + done: make(chan struct{}), + err: nil, } enforceDeadline = func(deadline time.Time) { diff --git a/util/contextflexibletimeout_test.go b/util/contextflexibletimeout_test.go index 77031d5..e6a1128 100644 --- a/util/contextflexibletimeout_test.go +++ b/util/contextflexibletimeout_test.go @@ -1,11 +1,11 @@ package util import ( - "testing" "context" - "time" - "github.com/stretchr/testify/require" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + "time" ) func TestContextWithOptionalDeadline(t *testing.T) { @@ -18,14 +18,14 @@ func TestContextWithOptionalDeadline(t *testing.T) { var cancellationError error go func() { select { - case <- cctx.Done(): + case <-cctx.Done(): receivedCancellation = time.Now() cancellationError = cctx.Err() - case <- time.After(600*time.Millisecond): + case <-time.After(600 * time.Millisecond): t.Fatalf("should have been cancelled by deadline") } }() - time.Sleep(100*time.Millisecond) + time.Sleep(100 * time.Millisecond) if !receivedCancellation.IsZero() { t.Fatalf("no enforcement means no cancellation") } @@ -33,11 +33,11 @@ func TestContextWithOptionalDeadline(t *testing.T) { dl, ok := cctx.Deadline() require.False(t, ok) require.Zero(t, dl) - enforceDeadline(begin.Add(200*time.Millisecond)) + enforceDeadline(begin.Add(200 * time.Millisecond)) // second call must be ignored, i.e. we expect the deadline to be at begin+200ms, not begin+400ms - enforceDeadline(begin.Add(400*time.Millisecond)) + enforceDeadline(begin.Add(400 * time.Millisecond)) - time.Sleep(300*time.Millisecond) // 100ms margin for scheduler + time.Sleep(300 * time.Millisecond) // 100ms margin for scheduler if receivedCancellation.Sub(begin) > 250*time.Millisecond { t.Fatalf("cancellation is beyond acceptable scheduler latency") } @@ -47,7 +47,7 @@ func TestContextWithOptionalDeadline(t *testing.T) { func TestContextWithOptionalDeadlineNegativeDeadline(t *testing.T) { ctx := context.Background() cctx, enforceDeadline := ContextWithOptionalDeadline(ctx) - enforceDeadline(time.Now().Add(-10*time.Second)) + enforceDeadline(time.Now().Add(-10 * time.Second)) select { case <-cctx.Done(): default: @@ -62,10 +62,10 @@ func TestContextWithOptionalDeadlineParentCancellation(t *testing.T) { // 0 ms start := time.Now() - enforceDeadline(start.Add(400*time.Millisecond)) - time.Sleep(100*time.Millisecond) - cancel() // cancel @ ~100ms - time.Sleep(100*time.Millisecond) // give 100ms time to propagate cancel + enforceDeadline(start.Add(400 * time.Millisecond)) + time.Sleep(100 * time.Millisecond) + cancel() // cancel @ ~100ms + time.Sleep(100 * time.Millisecond) // give 100ms time to propagate cancel // @ ~200ms select { case <-cctx.Done(): @@ -81,4 +81,4 @@ func TestContextWithOptionalDeadlineValue(t *testing.T) { pctx := context.WithValue(context.Background(), "key", "value") cctx, _ := ContextWithOptionalDeadline(pctx) assert.Equal(t, "value", cctx.Value("key")) -} \ No newline at end of file +} diff --git a/util/io.go b/util/io.go index 857df26..969e9c7 100644 --- a/util/io.go +++ b/util/io.go @@ -14,7 +14,7 @@ type NetConnLogger struct { func NewNetConnLogger(conn net.Conn, readlog, writelog string) (l *NetConnLogger, err error) { l = &NetConnLogger{ - Conn: conn, + Conn: conn, } flags := os.O_CREATE | os.O_WRONLY if readlog != "" { diff --git a/zfs/diff.go b/zfs/diff.go index c3564a1..e7a7e0c 100644 --- a/zfs/diff.go +++ b/zfs/diff.go @@ -5,9 +5,9 @@ import ( "crypto/sha512" "encoding/hex" "fmt" + "io" "os/exec" "sort" - "io" ) type fsbyCreateTXG []FilesystemVersion @@ -255,7 +255,7 @@ func ZFSIsPlaceholderFilesystem(p *DatasetPath) (isPlaceholder bool, err error) } else if err != nil { return false, err } - isPlaceholder, _ = IsPlaceholder(p, props.Get(ZREPL_PLACEHOLDER_PROPERTY_NAME)) + isPlaceholder, _ = IsPlaceholder(p, props.Get(ZREPL_PLACEHOLDER_PROPERTY_NAME)) return } diff --git a/zfs/mapping.go b/zfs/mapping.go index 8fcbd9a..56a85b3 100644 --- a/zfs/mapping.go +++ b/zfs/mapping.go @@ -39,7 +39,7 @@ func ZFSListMappingProperties(filter DatasetFilter, properties []string) (datase panic("properties must not contain 'name'") } } - newProps := make([]string, len(properties) + 1) + newProps := make([]string, len(properties)+1) newProps[0] = "name" copy(newProps[1:], properties) properties = newProps @@ -69,7 +69,7 @@ func ZFSListMappingProperties(filter DatasetFilter, properties []string) (datase } if pass { datasets = append(datasets, ZFSListMappingPropertiesResult{ - Path: path, + Path: path, Fields: r.Fields[1:], }) } @@ -78,5 +78,3 @@ func ZFSListMappingProperties(filter DatasetFilter, properties []string) (datase return } - - diff --git a/zfs/versions.go b/zfs/versions.go index 552af35..4bf2d40 100644 --- a/zfs/versions.go +++ b/zfs/versions.go @@ -6,10 +6,10 @@ import ( "errors" "fmt" "github.com/prometheus/client_golang/prometheus" + "io" "strconv" "strings" "time" - "io" ) type VersionType string