<commit_before>package barcode

import (
	"bytes"
	bar "github.com/boombuler/barcode"
	"github.com/boombuler/barcode/qr"
	"github.com/hackform/governor"
	"github.com/sirupsen/logrus"
	"image/png"
	"net/http"
)

const (
	moduleID  = "barcode"
	barQRSize = 256
)

const (
	// TransportQRCode is a type constant for QRCode
	TransportQRCode = iota
)

type (
	// Generator is a service that encodes data into barcodes
	Generator interface {
		Generate(data string, transport int) (*bytes.Buffer, *governor.Error)
	}

	barcodeService struct {
		encoder *png.Encoder
		log     *logrus.Logger
	}
)

// New returns a new barcode service
func New(conf governor.Config, l *logrus.Logger) Generator {
	l.Info("initialized barcode service")

	return &barcodeService{
		encoder: &png.Encoder{
			CompressionLevel: png.BestCompression,
		},
		log: l,
	}
}

const (
	moduleIDGenerate = moduleID + ".Generate"
)

// Generate encodes data as a barcode image represented by a bytes Buffer
func (b *barcodeService) Generate(data string, transport int) (*bytes.Buffer, *governor.Error) {
	switch transport {
	case TransportQRCode:
		qrCode, err := qr.Encode(data, qr.H, qr.Unicode)
		if err != nil {
			return nil, governor.NewError(moduleIDGenerate, err.Error(), 0, http.StatusInternalServerError)
		}

		qrCode, err = bar.Scale(qrCode, barQRSize, barQRSize)
		if err != nil {
			return nil, governor.NewError(moduleIDGenerate, err.Error(), 0, http.StatusInternalServerError)
		}

		buf := &bytes.Buffer{}
		if err := b.encoder.Encode(buf, qrCode); err != nil {
			return nil, governor.NewError(moduleIDGenerate, err.Error(), 0, http.StatusInternalServerError)
		}

		return buf, nil
	}<commit_msg>Improve clarity of barcode generation method name<commit_after>package barcode

import (
	"bytes"
	bar "github.com/boombuler/barcode"
	"github.com/boombuler/barcode/qr"
	"github.com/hackform/governor"
	"github.com/sirupsen/logrus"
	"image/png"
	"net/http"
)

const (
	moduleID  = "barcode"
	barQRSize = 256
)

const (
	// TransportQRCode is a type constant for QRCode
	TransportQRCode = iota
)

type (
	// Generator is a service that encodes data into barcodes
	Generator interface {
		GenerateBarcode(transport int, data string) (*bytes.Buffer, *governor.Error)
	}

	barcodeService struct {
		encoder *png.Encoder
		log     *logrus.Logger
	}
)

// New returns a new barcode service
func New(conf governor.Config, l *logrus.Logger) Generator {
	l.Info("initialized barcode service")

	return &barcodeService{
		encoder: &png.Encoder{
			CompressionLevel: png.BestCompression,
		},
		log: l,
	}
}

const (
	moduleIDGenerate = moduleID + ".Generate"
)

// GenerateBarcode encodes data as a barcode image represented by a bytes Buffer
func (b *barcodeService) GenerateBarcode(transport int, data string) (*bytes.Buffer, *governor.Error) {
	switch transport {
	case TransportQRCode:
		qrCode, err := qr.Encode(data, qr.H, qr.Unicode)
		if err != nil {
			return nil, governor.NewError(moduleIDGenerate, err.Error(), 0, http.StatusInternalServerError)
		}

		qrCode, err = bar.Scale(qrCode, barQRSize, barQRSize)
		if err != nil {
			return nil, governor.NewError(moduleIDGenerate, err.Error(), 0, http.StatusInternalServerError)
		}

		buf := &bytes.Buffer{}
		if err := b.encoder.Encode(buf, qrCode); err != nil {
			return nil, governor.NewError(moduleIDGenerate, err.Error(), 0, http.StatusInternalServerError)
		}

		return buf, nil
	}
{'fraction_non_alphanumeric': 0.11661295048344565, 'fraction_numerical': 0.0035159683562847933, 'mean_word_length': 4.212213740458015, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1330656', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1156, 'n_words': 300}