<commit_before>package rabbit

import (
	"errors"
	"fmt"

	"github.com/nu7hatch/gouuid"
	"github.com/streadway/amqp"
)

type RabbitChannel struct {
	uuid       string
	connection *amqp.Connection
	channel    *amqp.Channel
}

func NewRabbitChannel(conn *amqp.Connection) (*RabbitChannel, error) {
	id, err := uuid.NewV4()
	if err != nil {
		return nil, err
	}
	rabbitCh := &RabbitChannel{
		uuid:       id.String(),
		connection: conn,
	}
	if err := rabbitCh.Connect(); err != nil {
		return nil, err
	}
	return rabbitCh, nil

}

func (r *RabbitChannel) Connect() error {
	var err error
	r.channel, err = r.connection.Channel()
	if err != nil {
		return err
	}
	return nil
}

func (r *RabbitChannel) Close() error {
	if r.channel == nil {
		return errors.New("Channel is nil")
	}
	return r.channel.Close()
}

func (r *RabbitChannel) Publish(exchange, routingKey string, message amqp.Publishing) error {
	if r.channel == nil {
		return errors.New("Channel is nil")
	}
	return r.channel.Publish(exchange, routingKey, false, false, message)
}

func (r *RabbitChannel) DeclareExchange(exchange string) error {
	return r.channel.ExchangeDeclare(exchange, "topic", false, false, false, false, nil)
}

func (r *RabbitChannel) DeclareQueue(queue string) error {
	_, err := r.channel.QueueDeclare(queue, false, true, false, false, nil)
	return err
}

func (r *RabbitChannel) DeclareDurableQueue(queue string) error {
	_, err := r.channel.QueueDeclare(queue, true, false, false, false, nil)
	return err
}

func (r *RabbitChannel) DeclareReplyQueue(queue string) error {
	_, err := r.channel.QueueDeclare(queue, false, true, true, false, nil)
	return err
}

func (r *RabbitChannel) ConsumeQueue(queue string) (<-chan amqp.Delivery, error) {
	return r.channel.Consume(queue, r.uuid, false, false, false, false, nil)
}

func (r *RabbitChannel) BindQueue(queue, exchange string) error {
	return r.channel.QueueBind(queue, fmt.Sprintf("%s.#", queue), exchange, false, nil)
}<commit_msg>Expand and document fields passed when creating queues and exchanges<commit_after>package rabbit

import (
	"errors"
	"fmt"

	"github.com/nu7hatch/gouuid"
	"github.com/streadway/amqp"
)

type RabbitChannel struct {
	uuid       string
	connection *amqp.Connection
	channel    *amqp.Channel
}

func NewRabbitChannel(conn *amqp.Connection) (*RabbitChannel, error) {
	id, err := uuid.NewV4()
	if err != nil {
		return nil, err
	}
	rabbitCh := &RabbitChannel{
		uuid:       id.String(),
		connection: conn,
	}
	if err := rabbitCh.Connect(); err != nil {
		return nil, err
	}
	return rabbitCh, nil

}

func (r *RabbitChannel) Connect() error {
	var err error
	r.channel, err = r.connection.Channel()
	if err != nil {
		return err
	}
	return nil
}

func (r *RabbitChannel) Close() error {
	if r.channel == nil {
		return errors.New("Channel is nil")
	}
	return r.channel.Close()
}

func (r *RabbitChannel) Publish(exchange, routingKey string, message amqp.Publishing) error {
	if r.channel == nil {
		return errors.New("Channel is nil")
	}
	return r.channel.Publish(exchange, routingKey, false, false, message)
}

func (r *RabbitChannel) DeclareExchange(exchange string) error {
	return r.channel.ExchangeDeclare(
		exchange, // name
		"topic",  // kind
		false,    // durable
		false,    // autoDelete
		false,    // internal
		false,    // noWait
		nil,      // args
	)
}

func (r *RabbitChannel) DeclareQueue(queue string) error {
	_, err := r.channel.QueueDeclare(
		queue, // name
		false, // durable
		true,  // autoDelete
		false, // exclusive
		false, // noWait
		nil,   // args
	)
	return err
}

func (r *RabbitChannel) DeclareDurableQueue(queue string) error {
	_, err := r.channel.QueueDeclare(
		queue, // name
		true,  // durable
		false, // autoDelete
		false, // exclusive
		false, // noWait
		nil,   // args
	)
	return err
}

func (r *RabbitChannel) DeclareReplyQueue(queue string) error {
	_, err := r.channel.QueueDeclare(
		queue, // name
		false, // durable
		true,  // autoDelete
		true,  // exclusive
		false, // noWait
		nil,   // args
	)
	return err
}

func (r *RabbitChannel) ConsumeQueue(queue string) (<-chan amqp.Delivery, error) {
	return r.channel.Consume(
		queue,  // queue
		r.uuid, // consumer
		false,  // autoAck
		false,  // exclusive
		false,  // nolocal
		false,  // nowait
		nil,    // args
	)
}

func (r *RabbitChannel) BindQueue(queue, exchange string) error {
	return r.channel.QueueBind(queue, fmt.Sprintf("%s.#", queue), exchange, false, nil)
}
{'fraction_non_alphanumeric': 0.13319856244384545, 'fraction_numerical': 0.0008984725965858042, 'mean_word_length': 3.5954592363261093, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2082475', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1550, 'n_words': 426}