github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/queue/queueOperation.go (about)

     1  package queue
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/mundipagg/boleto-api/log"
     7  
     8  	"github.com/streadway/amqp"
     9  )
    10  
    11  var (
    12  	conn *amqp.Connection
    13  	l    *log.Log
    14  )
    15  
    16  // OpenConnectionReadOnly Abre conexão de leitura com RabbitMQ
    17  func OpenConnection() error {
    18  	l = log.CreateLog()
    19  	var err error
    20  	conn, err = openConnection()
    21  
    22  	return err
    23  }
    24  
    25  // GetConnectionReadOnly Obtém conexão de leitura com RabbitMQ
    26  func GetConnection() *amqp.Connection {
    27  	return conn
    28  }
    29  
    30  // CloseConnection close RabbitMQ connection
    31  func CloseConnection() error {
    32  	if conn == nil {
    33  		return nil
    34  	}
    35  
    36  	return conn.Close()
    37  }
    38  
    39  func failOnError(err error, title string, op string, msg ...string) {
    40  	if err != nil {
    41  		if msg != nil && msg[0] != "" {
    42  			l.Warn(msg[0], fmt.Sprintf("%s - %s - %s", op, title, err))
    43  		} else {
    44  			l.Operation = op
    45  			l.ErrorWithBasic(title, "Error", err)
    46  		}
    47  	}
    48  }