all: reduce newline overuse

This commit is contained in:
Aleksandr Razumov
2019-03-08 22:12:06 +03:00
parent a0ce368926
commit ce5eeedaab
4 changed files with 10 additions and 39 deletions

View File

@@ -275,9 +275,7 @@ type StopErr struct {
}
func (e StopErr) Error() string {
return fmt.Sprintf("error while stopping due to %s: %s",
sprintErr(e.Cause), sprintErr(e.Err),
)
return fmt.Sprintf("error while stopping due to %s: %s", sprintErr(e.Cause), sprintErr(e.Err))
}
// CloseErr indicates client close failure.
@@ -294,9 +292,7 @@ func sprintErr(err error) string {
}
func (c CloseErr) Error() string {
return fmt.Sprintf("failed to close: %s (connection), %s (agent)",
sprintErr(c.ConnectionErr), sprintErr(c.AgentErr),
)
return fmt.Sprintf("failed to close: %s (connection), %s (agent)", sprintErr(c.ConnectionErr), sprintErr(c.AgentErr))
}
func (c *Client) readUntilClosed() {

View File

@@ -16,14 +16,7 @@ const credentialsSep = ":"
// NewLongTermIntegrity returns new MessageIntegrity with key for long-term
// credentials. Password, username, and realm must be SASL-prepared.
func NewLongTermIntegrity(username, realm, password string) MessageIntegrity {
k := strings.Join(
[]string{
username,
realm,
password,
},
credentialsSep,
)
k := strings.Join([]string{username, realm, password}, credentialsSep)
// #nosec
h := md5.New()
fmt.Fprint(h, k)

View File

@@ -93,12 +93,8 @@ func (m *Message) NewTransactionID() error {
}
func (m *Message) String() string {
return fmt.Sprintf("%s l=%d attrs=%d id=%s",
m.Type,
m.Length,
len(m.Attributes),
base64.StdEncoding.EncodeToString(m.TransactionID[:]),
)
tID := base64.StdEncoding.EncodeToString(m.TransactionID[:])
return fmt.Sprintf("%s l=%d attrs=%d id=%s", m.Type, m.Length, len(m.Attributes), tID)
}
// Reset resets Message, attributes and underlying buffer length.
@@ -336,17 +332,11 @@ func (m *Message) Decode() error {
fullSize = messageHeaderSize + size // len(m.Raw)
)
if cookie != magicCookie {
msg := fmt.Sprintf(
"%x is invalid magic cookie (should be %x)",
cookie, magicCookie,
)
msg := fmt.Sprintf("%x is invalid magic cookie (should be %x)", cookie, magicCookie)
return newDecodeErr("message", "cookie", msg)
}
if len(buf) < fullSize {
msg := fmt.Sprintf(
"buffer length %d is less than %d (expected message size)",
len(buf), fullSize,
)
msg := fmt.Sprintf("buffer length %d is less than %d (expected message size)", len(buf), fullSize)
return newAttrDecodeErr("message", msg)
}
// saving header data
@@ -362,10 +352,7 @@ func (m *Message) Decode() error {
for offset < size {
// checking that we have enough bytes to read header
if len(b) < attributeHeaderSize {
msg := fmt.Sprintf(
"buffer length %d is less than %d (expected header size)",
len(b), attributeHeaderSize,
)
msg := fmt.Sprintf("buffer length %d is less than %d (expected header size)", len(b), attributeHeaderSize)
return newAttrDecodeErr("header", msg)
}
var (
@@ -379,10 +366,7 @@ func (m *Message) Decode() error {
b = b[attributeHeaderSize:] // slicing again to simplify value read
offset += attributeHeaderSize
if len(b) < aBuffL { // checking size
msg := fmt.Sprintf(
"buffer length %d is less than %d (expected value size for %s)",
len(b), aBuffL, a.Type,
)
msg := fmt.Sprintf("buffer length %d is less than %d (expected value size for %s)", len(b), aBuffL, a.Type)
return newAttrDecodeErr("value", msg)
}
a.Value = b[:aL]

View File

@@ -56,9 +56,7 @@ func (a *UnknownAttributes) GetFrom(m *Message) error {
first := 0
for first < len(v) {
last := first + attrTypeSize
*a = append(*a,
AttrType(bin.Uint16(v[first:last])),
)
*a = append(*a, AttrType(bin.Uint16(v[first:last])))
first = last
}
return nil