From a930334f2cfd404016dcdb890d06130029fd6ec3 Mon Sep 17 00:00:00 2001 From: linlin Date: Mon, 27 Sep 2021 17:05:12 +0800 Subject: [PATCH] fix some typos and add some comments to constants.go --- conn.go | 12 ++++++------ constants.go | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/conn.go b/conn.go index c5a71a94..43656c74 100644 --- a/conn.go +++ b/conn.go @@ -28,7 +28,7 @@ import ( var ErrNoServer = errors.New("zk: could not connect to a server") // ErrInvalidPath indicates that an operation was being attempted on -// an invalid path. (e.g. empty path) +// an invalid path. (e.g. empty path). var ErrInvalidPath = errors.New("zk: invalid path") // DefaultLogger uses the stdlib log package for logging. @@ -243,7 +243,7 @@ func WithHostProvider(hostProvider HostProvider) connOption { } } -// WithLogger returns a connection option specifying a non-default Logger +// WithLogger returns a connection option specifying a non-default Logger. func WithLogger(logger Logger) connOption { return func(c *Conn) { c.logger = logger @@ -251,7 +251,7 @@ func WithLogger(logger Logger) connOption { } // WithLogInfo returns a connection option specifying whether or not information messages -// shoud be logged. +// should be logged. func WithLogInfo(logInfo bool) connOption { return func(c *Conn) { c.logInfo = logInfo @@ -301,7 +301,7 @@ func WithMaxBufferSize(maxBufferSize int) connOption { } // WithMaxConnBufferSize sets maximum buffer size used to send and encode -// packets to Zookeeper server. The standard Zookeepeer client for java defaults +// packets to Zookeeper server. The standard Zookeeper client for java defaults // to a limit of 1mb. This option should be used for non-standard server setup // where znode is bigger than default 1mb. func WithMaxConnBufferSize(maxBufferSize int) connOption { @@ -947,7 +947,7 @@ func (c *Conn) AddAuth(scheme string, auth []byte) error { // Remember authdata so that it can be re-submitted on reconnect // // FIXME(prozlach): For now we treat "userfoo:passbar" and "userfoo:passbar2" - // as two different entries, which will be re-submitted on reconnet. Some + // as two different entries, which will be re-submitted on reconnect. Some // research is needed on how ZK treats these cases and // then maybe switch to something like "map[username] = password" to allow // only single password for given user with users being unique. @@ -1376,7 +1376,7 @@ func resendZkAuth(ctx context.Context, c *Conn) error { return ctx.Err() } if res.err != nil { - return fmt.Errorf("failed conneciton setAuth request: %v", res.err) + return fmt.Errorf("failed connection setAuth request: %v", res.err) } } diff --git a/constants.go b/constants.go index d914301f..84455d2b 100644 --- a/constants.go +++ b/constants.go @@ -7,7 +7,7 @@ import ( const ( protocolVersion = 0 - + // DefaultPort is the default port listened by server. DefaultPort = 2181 ) @@ -38,11 +38,13 @@ const ( ) const ( + // EventNodeCreated represents a node is created. EventNodeCreated EventType = 1 EventNodeDeleted EventType = 2 EventNodeDataChanged EventType = 3 EventNodeChildrenChanged EventType = 4 + // EventSession represents a session event. EventSession EventType = -1 EventNotWatching EventType = -2 ) @@ -59,6 +61,7 @@ var ( ) const ( + // StateUnknown means the session state is unknown. StateUnknown State = -1 StateDisconnected State = 0 StateConnecting State = 1 @@ -72,6 +75,7 @@ const ( ) const ( + // FlagEphemeral means the node is ephemeral. FlagEphemeral = 1 FlagSequence = 2 FlagTTL = 4 @@ -91,8 +95,10 @@ var ( } ) +// State is the session state. type State int32 +// String converts State to a readable string. func (s State) String() string { if name := stateNames[s]; name != "" { return name @@ -100,9 +106,11 @@ func (s State) String() string { return "Unknown" } +// ErrCode is the error code defined by server. Refer to ZK documentations for more specifics. type ErrCode int32 var ( + // ErrConnectionClosed means the connection has been closed. ErrConnectionClosed = errors.New("zk: connection closed") ErrUnknown = errors.New("zk: unknown error") ErrAPIError = errors.New("zk: api error") @@ -117,7 +125,7 @@ var ( ErrInvalidFlags = errors.New("zk: invalid flags specified") ErrAuthFailed = errors.New("zk: client authentication failed") ErrClosing = errors.New("zk: zookeeper is closing") - ErrNothing = errors.New("zk: no server responsees to process") + ErrNothing = errors.New("zk: no server responses to process") ErrSessionMoved = errors.New("zk: session moved to another server, so operation is ignored") ErrReconfigDisabled = errors.New("attempts to perform a reconfiguration operation when reconfiguration feature is disabled") ErrBadArguments = errors.New("invalid arguments") @@ -184,6 +192,7 @@ const ( // Constants for ACL permissions const ( + // PermRead represents the permission needed to read a znode. PermRead = 1 << iota PermWrite PermCreate @@ -220,6 +229,7 @@ var ( } ) +// EventType represents the event type sent by server. type EventType int32 func (t EventType) String() string {