diff --git a/_examples/client/client.go b/_examples/client/client.go index 58cf883..e375653 100644 --- a/_examples/client/client.go +++ b/_examples/client/client.go @@ -180,7 +180,6 @@ func (client *Client) handleReconnect(addr string) { client.infolog.Println("attempting to connect") conn, err := client.connect(addr) - if err != nil { client.errlog.Println("failed to connect. Retrying...") @@ -201,7 +200,6 @@ func (client *Client) handleReconnect(addr string) { // connect will create a new AMQP connection func (client *Client) connect(addr string) (*amqp.Connection, error) { conn, err := amqp.Dial(addr) - if err != nil { return nil, err } @@ -220,7 +218,6 @@ func (client *Client) handleReInit(conn *amqp.Connection) bool { client.m.Unlock() err := client.init(conn) - if err != nil { client.errlog.Println("failed to initialize channel, retrying...") @@ -250,13 +247,11 @@ func (client *Client) handleReInit(conn *amqp.Connection) bool { // init will initialize channel & declare queue func (client *Client) init(conn *amqp.Connection) error { ch, err := conn.Channel() - if err != nil { return err } err = ch.Confirm(false) - if err != nil { return err } @@ -268,7 +263,6 @@ func (client *Client) init(conn *amqp.Connection) error { false, // No-wait nil, // Arguments ) - if err != nil { return err } diff --git a/_examples/producer/producer.go b/_examples/producer/producer.go index 2d91cc2..8a63c73 100644 --- a/_examples/producer/producer.go +++ b/_examples/producer/producer.go @@ -5,12 +5,13 @@ package main import ( "flag" - amqp "github.com/rabbitmq/amqp091-go" "log" "os" "os/signal" "syscall" "time" + + amqp "github.com/rabbitmq/amqp091-go" ) var ( diff --git a/_examples/pubsub/pubsub.go b/_examples/pubsub/pubsub.go index 1d67823..530bdf6 100644 --- a/_examples/pubsub/pubsub.go +++ b/_examples/pubsub/pubsub.go @@ -12,10 +12,11 @@ import ( "crypto/sha1" "flag" "fmt" - amqp "github.com/rabbitmq/amqp091-go" "io" "log" "os" + + amqp "github.com/rabbitmq/amqp091-go" ) var url = flag.String("url", "amqp:///", "AMQP url for both the publisher and subscriber") diff --git a/allocator_test.go b/allocator_test.go index 2accbf0..bb1c28e 100644 --- a/allocator_test.go +++ b/allocator_test.go @@ -95,7 +95,6 @@ func TestAllocatorShouldNotReuseEarly(t *testing.T) { if want, got := first, third; want != got { t.Fatalf("expected third allocation to be %d, got: %d", want, got) } - } func TestAllocatorReleasesKeepUpWithAllocationsForAllSizes(t *testing.T) { diff --git a/auth.go b/auth.go index 0c07bb3..6df30f7 100644 --- a/auth.go +++ b/auth.go @@ -55,8 +55,7 @@ func (auth *AMQPlainAuth) Response() string { } // ExternalAuth for RabbitMQ-auth-mechanism-ssl. -type ExternalAuth struct { -} +type ExternalAuth struct{} // Mechanism returns "EXTERNAL" func (*ExternalAuth) Mechanism() string { @@ -70,7 +69,6 @@ func (*ExternalAuth) Response() string { // Finds the first mechanism preferred by the client that the server supports. func pickSASLMechanism(client []Authentication, serverMechanisms []string) (auth Authentication, ok bool) { - for _, auth = range client { for _, mech := range serverMechanisms { if auth.Mechanism() == mech { diff --git a/channel.go b/channel.go index 3dfd7fa..d08f918 100644 --- a/channel.go +++ b/channel.go @@ -1790,7 +1790,7 @@ it must be redelivered or dropped. See also Delivery.Nack */ -func (ch *Channel) Nack(tag uint64, multiple bool, requeue bool) error { +func (ch *Channel) Nack(tag uint64, multiple, requeue bool) error { ch.m.Lock() defer ch.m.Unlock() diff --git a/client_test.go b/client_test.go index 7d65881..abb277c 100644 --- a/client_test.go +++ b/client_test.go @@ -26,10 +26,12 @@ type server struct { tune connectionTuneOk } -var defaultLogin = "guest" -var defaultPassword = "guest" -var defaultPlainAuth = &PlainAuth{defaultLogin, defaultPassword} -var defaultAMQPlainAuth = &AMQPlainAuth{defaultLogin, defaultPassword} +var ( + defaultLogin = "guest" + defaultPassword = "guest" + defaultPlainAuth = &PlainAuth{defaultLogin, defaultPassword} + defaultAMQPlainAuth = &AMQPlainAuth{defaultLogin, defaultPassword} +) func defaultConfigWithAuth(auth Authentication) Config { return Config{ @@ -48,6 +50,8 @@ func amqplainConfig() Config { } func newServer(t *testing.T, serverIO, clientIO io.ReadWriteCloser) *server { + t.Helper() + return &server{ T: t, r: reader{serverIO}, @@ -58,6 +62,8 @@ func newServer(t *testing.T, serverIO, clientIO io.ReadWriteCloser) *server { } func newSession(t *testing.T) (io.ReadWriteCloser, *server) { + t.Helper() + rs, wc := io.Pipe() rc, ws := io.Pipe() @@ -228,7 +234,6 @@ func TestDefaultClientProperties(t *testing.T) { go func() { srv.connectionOpen() - }() if c, err := Open(rwc, defaultConfig()); err != nil { @@ -246,7 +251,6 @@ func TestDefaultClientProperties(t *testing.T) { if want, got := defaultLocale, srv.start.Locale; want != got { t.Errorf("expected locale %s got: %s", want, got) } - } func TestCustomClientProperties(t *testing.T) { @@ -261,7 +265,6 @@ func TestCustomClientProperties(t *testing.T) { go func() { srv.connectionOpen() - }() if c, err := Open(rwc, config); err != nil { @@ -275,7 +278,6 @@ func TestCustomClientProperties(t *testing.T) { if want, got := config.Properties["version"], srv.start.ClientProperties["version"]; want != got { t.Errorf("expected version %s got: %s", want, got) } - } func TestOpen(t *testing.T) { @@ -283,7 +285,6 @@ func TestOpen(t *testing.T) { t.Cleanup(func() { rwc.Close() }) go func() { srv.connectionOpen() - }() if c, err := Open(rwc, defaultConfig()); err != nil { @@ -333,7 +334,6 @@ func TestChannelOpen(t *testing.T) { go func() { srv.connectionOpen() srv.channelOpen(1) - }() c, err := Open(rwc, defaultConfig()) @@ -345,7 +345,6 @@ func TestChannelOpen(t *testing.T) { if err != nil { t.Fatalf("could not open channel: %v (%s)", ch, err) } - } func TestOpenFailedSASLUnsupportedMechanisms(t *testing.T) { @@ -361,7 +360,6 @@ func TestOpenFailedSASLUnsupportedMechanisms(t *testing.T) { if err != ErrSASL { t.Fatalf("expected ErrSASL got: %+v on %+v", err, c) } - } func TestOpenAMQPlainAuth(t *testing.T) { @@ -393,7 +391,6 @@ func TestOpenAMQPlainAuth(t *testing.T) { if table["PASSWORD"] != defaultPassword { t.Fatalf("unexpected password: want: %s, got: %s", defaultPassword, table["PASSWORD"]) } - } func TestOpenFailedCredentials(t *testing.T) { @@ -410,7 +407,6 @@ func TestOpenFailedCredentials(t *testing.T) { if err != ErrCredentials { t.Fatalf("expected ErrCredentials got: %+v on %+v", err, c) } - } func TestOpenFailedVhost(t *testing.T) { @@ -527,7 +523,6 @@ func TestConfirmMultipleOrdersDeliveryTags(t *testing.T) { t.Fatalf("failed ack, expected ack#%d to be %d, got %d", i, tag, ack.DeliveryTag) } } - } func TestDeferredConfirmations(t *testing.T) { diff --git a/connection.go b/connection.go index e167a23..127bb2d 100644 --- a/connection.go +++ b/connection.go @@ -675,7 +675,6 @@ func (c *Connection) dispatch0(f frame) { return case c.rpc <- m: } - } case *heartbeatFrame: // kthx - all reads reset our deadline. so we can drop this @@ -755,7 +754,6 @@ func (c *Connection) reader(r io.Reader) { for { frame, err := frames.ReadFrame() - if err != nil { c.shutdown(&Error{Code: FrameError, Reason: err.Error()}) return diff --git a/connection_test.go b/connection_test.go index 7eb7c30..2038359 100644 --- a/connection_test.go +++ b/connection_test.go @@ -375,6 +375,8 @@ func TestConnection_Close_WhenMemoryAlarmIsActive(t *testing.T) { } func rabbitmqctl(t *testing.T, args ...string) error { + t.Helper() + rabbitmqctlPath, found := os.LookupEnv(rabbitmqctlEnvKey) if !found { t.Skipf("variable for %s for rabbitmqctl not found, skipping", rabbitmqctlEnvKey) diff --git a/consumers.go b/consumers.go index c352fec..5434dce 100644 --- a/consumers.go +++ b/consumers.go @@ -55,7 +55,7 @@ func (subs *consumers) buffer(in chan *Delivery, out chan Delivery) { defer close(out) defer subs.Done() - var inflight = in + inflight := in var queue []*Delivery for delivery := range in { diff --git a/delivery.go b/delivery.go index e94cf34..f692abb 100644 --- a/delivery.go +++ b/delivery.go @@ -18,7 +18,7 @@ var errDeliveryNotInitialized = errors.New("delivery not initialized") // Applications can provide mock implementations in tests of Delivery handlers. type Acknowledger interface { Ack(tag uint64, multiple bool) error - Nack(tag uint64, multiple bool, requeue bool) error + Nack(tag uint64, multiple, requeue bool) error Reject(tag uint64, requeue bool) error } diff --git a/example_client_test.go b/example_client_test.go index a93c509..5122dc9 100644 --- a/example_client_test.go +++ b/example_client_test.go @@ -174,7 +174,6 @@ func (client *Client) handleReconnect(addr string) { client.logger.Println("Attempting to connect") conn, err := client.connect(addr) - if err != nil { client.logger.Println("Failed to connect. Retrying...") @@ -195,7 +194,6 @@ func (client *Client) handleReconnect(addr string) { // connect will create a new AMQP connection func (client *Client) connect(addr string) (*amqp.Connection, error) { conn, err := amqp.Dial(addr) - if err != nil { return nil, err } @@ -214,7 +212,6 @@ func (client *Client) handleReInit(conn *amqp.Connection) bool { client.m.Unlock() err := client.init(conn) - if err != nil { client.logger.Println("Failed to initialize channel. Retrying...") @@ -244,13 +241,11 @@ func (client *Client) handleReInit(conn *amqp.Connection) bool { // init will initialize channel & declare queue func (client *Client) init(conn *amqp.Connection) error { ch, err := conn.Channel() - if err != nil { return err } err = ch.Confirm(false) - if err != nil { return err } @@ -262,7 +257,6 @@ func (client *Client) init(conn *amqp.Connection) error { false, // No-wait nil, // Arguments ) - if err != nil { return err } diff --git a/examples_test.go b/examples_test.go index 39a064a..81795a1 100644 --- a/examples_test.go +++ b/examples_test.go @@ -202,7 +202,6 @@ func ExampleChannel_Confirm_bridge() { // And the body Body: msg.Body, }) - if err != nil { if e := msg.Nack(false, false); e != nil { log.Printf("nack error: %+v", e) diff --git a/integration_test.go b/integration_test.go index b600d59..7d0d93c 100644 --- a/integration_test.go +++ b/integration_test.go @@ -351,7 +351,6 @@ func TestIntegrationBasicQueueOperations(t *testing.T) { deleteQueueFirstOptions := []bool{true, false} for _, deleteQueueFirst := range deleteQueueFirstOptions { - if err := channel.ExchangeDeclare( exchangeName, // name "direct", // type @@ -403,7 +402,6 @@ func TestIntegrationBasicQueueOperations(t *testing.T) { t.Fatalf("delete exchange (after delete queue): %s", err) } t.Logf("delete exchange (after delete queue) OK") - } else { // deleteExchangeFirst if err := channel.ExchangeDelete(exchangeName, false, false); err != nil { t.Fatalf("delete exchange (first): %s", err) @@ -557,7 +555,6 @@ func TestIntegrationChannelClosing(t *testing.T) { } t.Logf("created/closed %d channels OK", n) } - } } @@ -887,8 +884,8 @@ func (c Publishing) Generate(r *rand.Rand, _ int) reflect.Value { var t reflect.Value p := Publishing{} - //p.DeliveryMode = uint8(r.Intn(3)) - //p.Priority = uint8(r.Intn(8)) + // p.DeliveryMode = uint8(r.Intn(3)) + // p.Priority = uint8(r.Intn(8)) if r.Intn(2) > 0 { p.ContentType = "application/octet-stream" @@ -899,23 +896,23 @@ func (c Publishing) Generate(r *rand.Rand, _ int) reflect.Value { } if r.Intn(2) > 0 { - p.CorrelationId = fmt.Sprintf("%d", r.Int()) + p.CorrelationId = strconv.Itoa(r.Int()) } if r.Intn(2) > 0 { - p.ReplyTo = fmt.Sprintf("%d", r.Int()) + p.ReplyTo = strconv.Itoa(r.Int()) } if r.Intn(2) > 0 { - p.MessageId = fmt.Sprintf("%d", r.Int()) + p.MessageId = strconv.Itoa(r.Int()) } if r.Intn(2) > 0 { - p.Type = fmt.Sprintf("%d", r.Int()) + p.Type = strconv.Itoa(r.Int()) } if r.Intn(2) > 0 { - p.AppId = fmt.Sprintf("%d", r.Int()) + p.AppId = strconv.Itoa(r.Int()) } if r.Intn(2) > 0 { @@ -1166,7 +1163,6 @@ func TestIntegrationGetOk(t *testing.T) { } msg, ok, err := ch.Get(queue, false) - if err != nil { t.Fatalf("Failed get: %v", err) } @@ -1193,7 +1189,6 @@ func TestIntegrationGetEmpty(t *testing.T) { } _, ok, err := ch.Get(queue, false) - if err != nil { t.Fatalf("Failed get: %v", err) } @@ -1263,7 +1258,6 @@ func TestIntegrationTxRollback(t *testing.T) { } _, ok, err := ch.Get(queue, false) - if err != nil { t.Fatalf("Failed get: %v", err) } @@ -1732,7 +1726,6 @@ func TestCorruptedMessageIssue7(t *testing.T) { err := pub.PublishWithContext(context.TODO(), "", queue, false, false, Publishing{ Body: generateCrc32Random(t, 7*i), }) - if err != nil { t.Fatalf("Failed to publish") } @@ -2116,6 +2109,8 @@ func TestShouldNotWaitAfterConnectionClosedIssue44(t *testing.T) { // Returns a connection to the AMQP if the AMQP_URL environment // variable is set and a connection can be established. func integrationConnection(t *testing.T, name string) *Connection { + t.Helper() + conf := defaultConfig() if conf.Properties == nil { conf.Properties = make(Table) @@ -2131,6 +2126,8 @@ func integrationConnection(t *testing.T, name string) *Connection { // Returns a connection, channel and declares a queue when the AMQP_URL is in the environment func integrationQueue(t *testing.T, name string) (*Connection, *Channel) { + t.Helper() + if conn := integrationConnection(t, name); conn != nil { if channel, err := conn.Channel(); err == nil { if _, err = channel.QueueDeclare(name, false, true, false, false, nil); err == nil { @@ -2142,6 +2139,8 @@ func integrationQueue(t *testing.T, name string) (*Connection, *Channel) { } func integrationQueueDelete(t *testing.T, c *Channel, queue string) { + t.Helper() + if c, err := c.QueueDelete(queue, false, false, false); err != nil { t.Fatalf("queue deletion failed, c: %d, err: %v", c, err) } @@ -2150,6 +2149,8 @@ func integrationQueueDelete(t *testing.T, c *Channel, queue string) { // Delegates to integrationConnection and only returns a connection if the // product is RabbitMQ func integrationRabbitMQ(t *testing.T, name string) *Connection { + t.Helper() + if conn := integrationConnection(t, name); conn != nil { if server, ok := conn.Properties["product"]; ok && server == "RabbitMQ" { return conn @@ -2160,6 +2161,8 @@ func integrationRabbitMQ(t *testing.T, name string) *Connection { } func assertConsumeBody(t *testing.T, messages <-chan Delivery, want []byte) (msg *Delivery) { + t.Helper() + select { case got := <-messages: if !bytes.Equal(want, got.Body) { @@ -2195,11 +2198,12 @@ func TestShouldNotWaitAfterConnectionClosedNewChannelCreatedIssue11(t *testing.T if err == nil { t.Fatalf("Opening a channel from a closed connection should not block but returning an error %v", err) } - } // Pulls out the CRC and verifies the remaining content against the CRC func assertMessageCrc32(t *testing.T, msg []byte, assert string) { + t.Helper() + size := binary.BigEndian.Uint32(msg[:4]) crc := crc32.NewIEEE() @@ -2217,6 +2221,8 @@ func assertMessageCrc32(t *testing.T, msg []byte, assert string) { // Creates a random body size with a leading 32-bit CRC in network byte order // that verifies the remaining slice func generateCrc32Random(t *testing.T, size int) []byte { + t.Helper() + msg := make([]byte, size+8) if _, err := io.ReadFull(devrand.Reader, msg); err != nil { t.Fatalf("could not get random data: %+v", err) diff --git a/log.go b/log.go index 7540f13..e337db3 100644 --- a/log.go +++ b/log.go @@ -16,8 +16,7 @@ func SetLogger(logger Logging) { Logger = logger } -type NullLogger struct { -} +type NullLogger struct{} func (l NullLogger) Printf(format string, v ...interface{}) { } diff --git a/read.go b/read.go index a8bed13..f015521 100644 --- a/read.go +++ b/read.go @@ -269,7 +269,7 @@ func readTable(r io.Reader) (table Table, err error) { return } - nested.Write([]byte(str)) + nested.WriteString(str) table = make(Table) @@ -291,11 +291,8 @@ func readTable(r io.Reader) (table Table, err error) { return } -func readArray(r io.Reader) ([]interface{}, error) { - var ( - size uint32 - err error - ) +func readArray(r io.Reader) (arr []interface{}, err error) { + var size uint32 if err = binary.Read(r, binary.BigEndian, &size); err != nil { return nil, err @@ -303,7 +300,6 @@ func readArray(r io.Reader) ([]interface{}, error) { var ( lim = &io.LimitedReader{R: r, N: int64(size)} - arr []interface{} field interface{} ) diff --git a/spec/gen.go b/spec/gen.go index 7b640f5..d5ce6fc 100644 --- a/spec/gen.go +++ b/spec/gen.go @@ -502,7 +502,6 @@ func public(parts ...string) string { func export(delim *regexp.Regexp, parts ...string) (res string) { for _, in := range parts { - res += delim.ReplaceAllStringFunc(in, func(match string) string { switch len(match) { case 1: @@ -526,7 +525,6 @@ func main() { } err = xml.Unmarshal(spec, &r.Root) - if err != nil { log.Fatalln("Could not parse XML:", err) } diff --git a/spec091.go b/spec091.go index 6e02ba9..cc24cf4 100644 --- a/spec091.go +++ b/spec091.go @@ -84,7 +84,6 @@ func (msg *connectionStart) wait() bool { } func (msg *connectionStart) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.VersionMajor); err != nil { return } @@ -107,7 +106,6 @@ func (msg *connectionStart) write(w io.Writer) (err error) { } func (msg *connectionStart) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.VersionMajor); err != nil { return } @@ -145,7 +143,6 @@ func (msg *connectionStartOk) wait() bool { } func (msg *connectionStartOk) write(w io.Writer) (err error) { - if err = writeTable(w, msg.ClientProperties); err != nil { return } @@ -166,7 +163,6 @@ func (msg *connectionStartOk) write(w io.Writer) (err error) { } func (msg *connectionStartOk) read(r io.Reader) (err error) { - if msg.ClientProperties, err = readTable(r); err != nil { return } @@ -199,7 +195,6 @@ func (msg *connectionSecure) wait() bool { } func (msg *connectionSecure) write(w io.Writer) (err error) { - if err = writeLongstr(w, msg.Challenge); err != nil { return } @@ -208,7 +203,6 @@ func (msg *connectionSecure) write(w io.Writer) (err error) { } func (msg *connectionSecure) read(r io.Reader) (err error) { - if msg.Challenge, err = readLongstr(r); err != nil { return } @@ -229,7 +223,6 @@ func (msg *connectionSecureOk) wait() bool { } func (msg *connectionSecureOk) write(w io.Writer) (err error) { - if err = writeLongstr(w, msg.Response); err != nil { return } @@ -238,7 +231,6 @@ func (msg *connectionSecureOk) write(w io.Writer) (err error) { } func (msg *connectionSecureOk) read(r io.Reader) (err error) { - if msg.Response, err = readLongstr(r); err != nil { return } @@ -261,7 +253,6 @@ func (msg *connectionTune) wait() bool { } func (msg *connectionTune) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.ChannelMax); err != nil { return } @@ -278,7 +269,6 @@ func (msg *connectionTune) write(w io.Writer) (err error) { } func (msg *connectionTune) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.ChannelMax); err != nil { return } @@ -309,7 +299,6 @@ func (msg *connectionTuneOk) wait() bool { } func (msg *connectionTuneOk) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.ChannelMax); err != nil { return } @@ -326,7 +315,6 @@ func (msg *connectionTuneOk) write(w io.Writer) (err error) { } func (msg *connectionTuneOk) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.ChannelMax); err != nil { return } @@ -408,7 +396,6 @@ func (msg *connectionOpenOk) wait() bool { } func (msg *connectionOpenOk) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.reserved1); err != nil { return } @@ -417,7 +404,6 @@ func (msg *connectionOpenOk) write(w io.Writer) (err error) { } func (msg *connectionOpenOk) read(r io.Reader) (err error) { - if msg.reserved1, err = readShortstr(r); err != nil { return } @@ -441,7 +427,6 @@ func (msg *connectionClose) wait() bool { } func (msg *connectionClose) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.ReplyCode); err != nil { return } @@ -461,7 +446,6 @@ func (msg *connectionClose) write(w io.Writer) (err error) { } func (msg *connectionClose) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.ReplyCode); err != nil { return } @@ -480,8 +464,7 @@ func (msg *connectionClose) read(r io.Reader) (err error) { return } -type connectionCloseOk struct { -} +type connectionCloseOk struct{} func (msg *connectionCloseOk) id() (uint16, uint16) { return 10, 51 @@ -492,12 +475,10 @@ func (msg *connectionCloseOk) wait() bool { } func (msg *connectionCloseOk) write(w io.Writer) (err error) { - return } func (msg *connectionCloseOk) read(r io.Reader) (err error) { - return } @@ -514,7 +495,6 @@ func (msg *connectionBlocked) wait() bool { } func (msg *connectionBlocked) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.Reason); err != nil { return } @@ -523,7 +503,6 @@ func (msg *connectionBlocked) write(w io.Writer) (err error) { } func (msg *connectionBlocked) read(r io.Reader) (err error) { - if msg.Reason, err = readShortstr(r); err != nil { return } @@ -531,8 +510,7 @@ func (msg *connectionBlocked) read(r io.Reader) (err error) { return } -type connectionUnblocked struct { -} +type connectionUnblocked struct{} func (msg *connectionUnblocked) id() (uint16, uint16) { return 10, 61 @@ -543,12 +521,10 @@ func (msg *connectionUnblocked) wait() bool { } func (msg *connectionUnblocked) write(w io.Writer) (err error) { - return } func (msg *connectionUnblocked) read(r io.Reader) (err error) { - return } @@ -566,7 +542,6 @@ func (msg *connectionUpdateSecret) wait() bool { } func (msg *connectionUpdateSecret) write(w io.Writer) (err error) { - if err = writeLongstr(w, msg.NewSecret); err != nil { return } @@ -579,7 +554,6 @@ func (msg *connectionUpdateSecret) write(w io.Writer) (err error) { } func (msg *connectionUpdateSecret) read(r io.Reader) (err error) { - if msg.NewSecret, err = readLongstr(r); err != nil { return } @@ -591,8 +565,7 @@ func (msg *connectionUpdateSecret) read(r io.Reader) (err error) { return } -type connectionUpdateSecretOk struct { -} +type connectionUpdateSecretOk struct{} func (msg *connectionUpdateSecretOk) id() (uint16, uint16) { return 10, 71 @@ -603,12 +576,10 @@ func (msg *connectionUpdateSecretOk) wait() bool { } func (msg *connectionUpdateSecretOk) write(w io.Writer) (err error) { - return } func (msg *connectionUpdateSecretOk) read(r io.Reader) (err error) { - return } @@ -625,7 +596,6 @@ func (msg *channelOpen) wait() bool { } func (msg *channelOpen) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.reserved1); err != nil { return } @@ -634,7 +604,6 @@ func (msg *channelOpen) write(w io.Writer) (err error) { } func (msg *channelOpen) read(r io.Reader) (err error) { - if msg.reserved1, err = readShortstr(r); err != nil { return } @@ -655,7 +624,6 @@ func (msg *channelOpenOk) wait() bool { } func (msg *channelOpenOk) write(w io.Writer) (err error) { - if err = writeLongstr(w, msg.reserved1); err != nil { return } @@ -664,7 +632,6 @@ func (msg *channelOpenOk) write(w io.Writer) (err error) { } func (msg *channelOpenOk) read(r io.Reader) (err error) { - if msg.reserved1, err = readLongstr(r); err != nil { return } @@ -762,7 +729,6 @@ func (msg *channelClose) wait() bool { } func (msg *channelClose) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.ReplyCode); err != nil { return } @@ -782,7 +748,6 @@ func (msg *channelClose) write(w io.Writer) (err error) { } func (msg *channelClose) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.ReplyCode); err != nil { return } @@ -801,8 +766,7 @@ func (msg *channelClose) read(r io.Reader) (err error) { return } -type channelCloseOk struct { -} +type channelCloseOk struct{} func (msg *channelCloseOk) id() (uint16, uint16) { return 20, 41 @@ -813,12 +777,10 @@ func (msg *channelCloseOk) wait() bool { } func (msg *channelCloseOk) write(w io.Writer) (err error) { - return } func (msg *channelCloseOk) read(r io.Reader) (err error) { - return } @@ -917,8 +879,7 @@ func (msg *exchangeDeclare) read(r io.Reader) (err error) { return } -type exchangeDeclareOk struct { -} +type exchangeDeclareOk struct{} func (msg *exchangeDeclareOk) id() (uint16, uint16) { return 40, 11 @@ -929,12 +890,10 @@ func (msg *exchangeDeclareOk) wait() bool { } func (msg *exchangeDeclareOk) write(w io.Writer) (err error) { - return } func (msg *exchangeDeclareOk) read(r io.Reader) (err error) { - return } @@ -999,8 +958,7 @@ func (msg *exchangeDelete) read(r io.Reader) (err error) { return } -type exchangeDeleteOk struct { -} +type exchangeDeleteOk struct{} func (msg *exchangeDeleteOk) id() (uint16, uint16) { return 40, 21 @@ -1011,12 +969,10 @@ func (msg *exchangeDeleteOk) wait() bool { } func (msg *exchangeDeleteOk) write(w io.Writer) (err error) { - return } func (msg *exchangeDeleteOk) read(r io.Reader) (err error) { - return } @@ -1098,8 +1054,7 @@ func (msg *exchangeBind) read(r io.Reader) (err error) { return } -type exchangeBindOk struct { -} +type exchangeBindOk struct{} func (msg *exchangeBindOk) id() (uint16, uint16) { return 40, 31 @@ -1110,12 +1065,10 @@ func (msg *exchangeBindOk) wait() bool { } func (msg *exchangeBindOk) write(w io.Writer) (err error) { - return } func (msg *exchangeBindOk) read(r io.Reader) (err error) { - return } @@ -1197,8 +1150,7 @@ func (msg *exchangeUnbind) read(r io.Reader) (err error) { return } -type exchangeUnbindOk struct { -} +type exchangeUnbindOk struct{} func (msg *exchangeUnbindOk) id() (uint16, uint16) { return 40, 51 @@ -1209,12 +1161,10 @@ func (msg *exchangeUnbindOk) wait() bool { } func (msg *exchangeUnbindOk) write(w io.Writer) (err error) { - return } func (msg *exchangeUnbindOk) read(r io.Reader) (err error) { - return } @@ -1321,7 +1271,6 @@ func (msg *queueDeclareOk) wait() bool { } func (msg *queueDeclareOk) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.Queue); err != nil { return } @@ -1337,7 +1286,6 @@ func (msg *queueDeclareOk) write(w io.Writer) (err error) { } func (msg *queueDeclareOk) read(r io.Reader) (err error) { - if msg.Queue, err = readShortstr(r); err != nil { return } @@ -1430,8 +1378,7 @@ func (msg *queueBind) read(r io.Reader) (err error) { return } -type queueBindOk struct { -} +type queueBindOk struct{} func (msg *queueBindOk) id() (uint16, uint16) { return 50, 21 @@ -1442,12 +1389,10 @@ func (msg *queueBindOk) wait() bool { } func (msg *queueBindOk) write(w io.Writer) (err error) { - return } func (msg *queueBindOk) read(r io.Reader) (err error) { - return } @@ -1468,7 +1413,6 @@ func (msg *queueUnbind) wait() bool { } func (msg *queueUnbind) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil { return } @@ -1491,7 +1435,6 @@ func (msg *queueUnbind) write(w io.Writer) (err error) { } func (msg *queueUnbind) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil { return } @@ -1513,8 +1456,7 @@ func (msg *queueUnbind) read(r io.Reader) (err error) { return } -type queueUnbindOk struct { -} +type queueUnbindOk struct{} func (msg *queueUnbindOk) id() (uint16, uint16) { return 50, 51 @@ -1525,12 +1467,10 @@ func (msg *queueUnbindOk) wait() bool { } func (msg *queueUnbindOk) write(w io.Writer) (err error) { - return } func (msg *queueUnbindOk) read(r io.Reader) (err error) { - return } @@ -1602,7 +1542,6 @@ func (msg *queuePurgeOk) wait() bool { } func (msg *queuePurgeOk) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.MessageCount); err != nil { return } @@ -1611,7 +1550,6 @@ func (msg *queuePurgeOk) write(w io.Writer) (err error) { } func (msg *queuePurgeOk) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.MessageCount); err != nil { return } @@ -1699,7 +1637,6 @@ func (msg *queueDeleteOk) wait() bool { } func (msg *queueDeleteOk) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.MessageCount); err != nil { return } @@ -1708,7 +1645,6 @@ func (msg *queueDeleteOk) write(w io.Writer) (err error) { } func (msg *queueDeleteOk) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.MessageCount); err != nil { return } @@ -1771,8 +1707,7 @@ func (msg *basicQos) read(r io.Reader) (err error) { return } -type basicQosOk struct { -} +type basicQosOk struct{} func (msg *basicQosOk) id() (uint16, uint16) { return 60, 11 @@ -1783,12 +1718,10 @@ func (msg *basicQosOk) wait() bool { } func (msg *basicQosOk) write(w io.Writer) (err error) { - return } func (msg *basicQosOk) read(r io.Reader) (err error) { - return } @@ -1894,7 +1827,6 @@ func (msg *basicConsumeOk) wait() bool { } func (msg *basicConsumeOk) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.ConsumerTag); err != nil { return } @@ -1903,7 +1835,6 @@ func (msg *basicConsumeOk) write(w io.Writer) (err error) { } func (msg *basicConsumeOk) read(r io.Reader) (err error) { - if msg.ConsumerTag, err = readShortstr(r); err != nil { return } @@ -1970,7 +1901,6 @@ func (msg *basicCancelOk) wait() bool { } func (msg *basicCancelOk) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.ConsumerTag); err != nil { return } @@ -1979,7 +1909,6 @@ func (msg *basicCancelOk) write(w io.Writer) (err error) { } func (msg *basicCancelOk) read(r io.Reader) (err error) { - if msg.ConsumerTag, err = readShortstr(r); err != nil { return } @@ -2091,7 +2020,6 @@ func (msg *basicReturn) setContent(props properties, body []byte) { } func (msg *basicReturn) write(w io.Writer) (err error) { - if err = binary.Write(w, binary.BigEndian, msg.ReplyCode); err != nil { return } @@ -2110,7 +2038,6 @@ func (msg *basicReturn) write(w io.Writer) (err error) { } func (msg *basicReturn) read(r io.Reader) (err error) { - if err = binary.Read(r, binary.BigEndian, &msg.ReplyCode); err != nil { return } @@ -2358,7 +2285,6 @@ func (msg *basicGetEmpty) wait() bool { } func (msg *basicGetEmpty) write(w io.Writer) (err error) { - if err = writeShortstr(w, msg.reserved1); err != nil { return } @@ -2367,7 +2293,6 @@ func (msg *basicGetEmpty) write(w io.Writer) (err error) { } func (msg *basicGetEmpty) read(r io.Reader) (err error) { - if msg.reserved1, err = readShortstr(r); err != nil { return } @@ -2541,8 +2466,7 @@ func (msg *basicRecover) read(r io.Reader) (err error) { return } -type basicRecoverOk struct { -} +type basicRecoverOk struct{} func (msg *basicRecoverOk) id() (uint16, uint16) { return 60, 111 @@ -2553,12 +2477,10 @@ func (msg *basicRecoverOk) wait() bool { } func (msg *basicRecoverOk) write(w io.Writer) (err error) { - return } func (msg *basicRecoverOk) read(r io.Reader) (err error) { - return } @@ -2614,8 +2536,7 @@ func (msg *basicNack) read(r io.Reader) (err error) { return } -type txSelect struct { -} +type txSelect struct{} func (msg *txSelect) id() (uint16, uint16) { return 90, 10 @@ -2626,17 +2547,14 @@ func (msg *txSelect) wait() bool { } func (msg *txSelect) write(w io.Writer) (err error) { - return } func (msg *txSelect) read(r io.Reader) (err error) { - return } -type txSelectOk struct { -} +type txSelectOk struct{} func (msg *txSelectOk) id() (uint16, uint16) { return 90, 11 @@ -2647,17 +2565,14 @@ func (msg *txSelectOk) wait() bool { } func (msg *txSelectOk) write(w io.Writer) (err error) { - return } func (msg *txSelectOk) read(r io.Reader) (err error) { - return } -type txCommit struct { -} +type txCommit struct{} func (msg *txCommit) id() (uint16, uint16) { return 90, 20 @@ -2668,17 +2583,14 @@ func (msg *txCommit) wait() bool { } func (msg *txCommit) write(w io.Writer) (err error) { - return } func (msg *txCommit) read(r io.Reader) (err error) { - return } -type txCommitOk struct { -} +type txCommitOk struct{} func (msg *txCommitOk) id() (uint16, uint16) { return 90, 21 @@ -2689,17 +2601,14 @@ func (msg *txCommitOk) wait() bool { } func (msg *txCommitOk) write(w io.Writer) (err error) { - return } func (msg *txCommitOk) read(r io.Reader) (err error) { - return } -type txRollback struct { -} +type txRollback struct{} func (msg *txRollback) id() (uint16, uint16) { return 90, 30 @@ -2710,17 +2619,14 @@ func (msg *txRollback) wait() bool { } func (msg *txRollback) write(w io.Writer) (err error) { - return } func (msg *txRollback) read(r io.Reader) (err error) { - return } -type txRollbackOk struct { -} +type txRollbackOk struct{} func (msg *txRollbackOk) id() (uint16, uint16) { return 90, 31 @@ -2731,12 +2637,10 @@ func (msg *txRollbackOk) wait() bool { } func (msg *txRollbackOk) write(w io.Writer) (err error) { - return } func (msg *txRollbackOk) read(r io.Reader) (err error) { - return } @@ -2777,8 +2681,7 @@ func (msg *confirmSelect) read(r io.Reader) (err error) { return } -type confirmSelectOk struct { -} +type confirmSelectOk struct{} func (msg *confirmSelectOk) id() (uint16, uint16) { return 85, 11 @@ -2789,12 +2692,10 @@ func (msg *confirmSelectOk) wait() bool { } func (msg *confirmSelectOk) write(w io.Writer) (err error) { - return } func (msg *confirmSelectOk) read(r io.Reader) (err error) { - return } diff --git a/tls_test.go b/tls_test.go index a3916dd..17203b2 100644 --- a/tls_test.go +++ b/tls_test.go @@ -16,6 +16,8 @@ import ( ) func tlsServerConfig(t *testing.T) *tls.Config { + t.Helper() + cfg := new(tls.Config) cfg.ClientCAs = x509.NewCertPool() @@ -33,6 +35,8 @@ func tlsServerConfig(t *testing.T) *tls.Config { } func tlsClientConfig(t *testing.T) *tls.Config { + t.Helper() + cfg := new(tls.Config) cfg.RootCAs = x509.NewCertPool() cfg.RootCAs.AppendCertsFromPEM([]byte(caCert)) @@ -56,6 +60,8 @@ type tlsServer struct { // Captures the header for each accepted connection func (s *tlsServer) Serve(t *testing.T) { + t.Helper() + for { c, err := s.Accept() if err != nil { @@ -66,6 +72,8 @@ func (s *tlsServer) Serve(t *testing.T) { } func startTLSServer(t *testing.T, cfg *tls.Config) tlsServer { + t.Helper() + l, err := tls.Listen("tcp", "127.0.0.1:3456", cfg) if err != nil { t.Fatalf("TLS server Listen error: %+v", err) diff --git a/types_test.go b/types_test.go index 08848de..dad4c27 100644 --- a/types_test.go +++ b/types_test.go @@ -67,7 +67,8 @@ func TestValidateField(t *testing.T) { simpleTypes := []interface{}{ nil, true, byte(1), int8(1), 10, int16(10), int32(10), int64(10), float32(1.0), float64(1.0), "string", []byte("byte slice"), - Decimal{Scale: 2, Value: 12345}, time.Now(), + Decimal{Scale: 2, Value: 12345}, + time.Now(), } for _, v := range simpleTypes { if err := validateField(v); err != nil { diff --git a/uri.go b/uri.go index ddc4b1a..4a148a3 100644 --- a/uri.go +++ b/uri.go @@ -14,8 +14,10 @@ import ( "strings" ) -var errURIScheme = errors.New("AMQP scheme must be either 'amqp://' or 'amqps://'") -var errURIWhitespace = errors.New("URI must not contain whitespace") +var ( + errURIScheme = errors.New("AMQP scheme must be either 'amqp://' or 'amqps://'") + errURIWhitespace = errors.New("URI must not contain whitespace") +) var schemePorts = map[string]int{ "amqp": 5672, diff --git a/write.go b/write.go index dcec314..3d15975 100644 --- a/write.go +++ b/write.go @@ -90,44 +90,44 @@ func (f *headerFrame) write(w io.Writer) (err error) { var mask uint16 - if len(f.Properties.ContentType) > 0 { - mask = mask | flagContentType + if f.Properties.ContentType != "" { + mask |= flagContentType } - if len(f.Properties.ContentEncoding) > 0 { - mask = mask | flagContentEncoding + if f.Properties.ContentEncoding != "" { + mask |= flagContentEncoding } if f.Properties.Headers != nil && len(f.Properties.Headers) > 0 { - mask = mask | flagHeaders + mask |= flagHeaders } if f.Properties.DeliveryMode > 0 { - mask = mask | flagDeliveryMode + mask |= flagDeliveryMode } if f.Properties.Priority > 0 { - mask = mask | flagPriority + mask |= flagPriority } - if len(f.Properties.CorrelationId) > 0 { - mask = mask | flagCorrelationId + if f.Properties.CorrelationId != "" { + mask |= flagCorrelationId } - if len(f.Properties.ReplyTo) > 0 { - mask = mask | flagReplyTo + if f.Properties.ReplyTo != "" { + mask |= flagReplyTo } - if len(f.Properties.Expiration) > 0 { - mask = mask | flagExpiration + if f.Properties.Expiration != "" { + mask |= flagExpiration } - if len(f.Properties.MessageId) > 0 { - mask = mask | flagMessageId + if f.Properties.MessageId != "" { + mask |= flagMessageId } if !f.Properties.Timestamp.IsZero() { - mask = mask | flagTimestamp + mask |= flagTimestamp } - if len(f.Properties.Type) > 0 { - mask = mask | flagType + if f.Properties.Type != "" { + mask |= flagType } - if len(f.Properties.UserId) > 0 { - mask = mask | flagUserId + if f.Properties.UserId != "" { + mask |= flagUserId } - if len(f.Properties.AppId) > 0 { - mask = mask | flagAppId + if f.Properties.AppId != "" { + mask |= flagAppId } if err = binary.Write(&payload, binary.BigEndian, mask); err != nil { @@ -224,7 +224,6 @@ func writeFrame(w io.Writer, typ uint8, channel uint16, payload []byte) (err err byte((size & 0x0000ff00) >> 8), byte((size & 0x000000ff) >> 0), }) - if err != nil { return } @@ -243,7 +242,7 @@ func writeFrame(w io.Writer, typ uint8, channel uint16, payload []byte) (err err func writeShortstr(w io.Writer, s string) (err error) { b := []byte(s) - var length = uint8(len(b)) + length := uint8(len(b)) if err = binary.Write(w, binary.BigEndian, length); err != nil { return @@ -259,7 +258,7 @@ func writeShortstr(w io.Writer, s string) (err error) { func writeLongstr(w io.Writer, s string) (err error) { b := []byte(s) - var length = uint32(len(b)) + length := uint32(len(b)) if err = binary.Write(w, binary.BigEndian, length); err != nil { return