Skip to content

Commit 3455352

Browse files
authored
fix: remove singleton code instance (#535)
1 parent 19e6574 commit 3455352

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

internal/code/code.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,23 @@ import (
77
"image/draw"
88
"image/png"
99

10-
"github.com/boombuler/barcode/code128"
11-
"github.com/boombuler/barcode/ean"
12-
"github.com/johnfercher/maroto/v2/pkg/consts/barcode"
13-
1410
libBarcode "github.com/boombuler/barcode"
11+
"github.com/boombuler/barcode/code128"
1512
"github.com/boombuler/barcode/datamatrix"
13+
"github.com/boombuler/barcode/ean"
1614
"github.com/boombuler/barcode/qr"
1715

16+
"github.com/johnfercher/maroto/v2/pkg/consts/barcode"
1817
"github.com/johnfercher/maroto/v2/pkg/consts/extension"
1918
"github.com/johnfercher/maroto/v2/pkg/core/entity"
2019
"github.com/johnfercher/maroto/v2/pkg/props"
2120
)
2221

23-
// codeInstance is the singleton of code, opted to use a singleton to ensure that
24-
// this will not be instantiated more than once since there is no need to do this
25-
// because code is stateless.
26-
var codeInstance *code = nil
27-
2822
type code struct{}
2923

3024
// New create a Code (Singleton).
3125
func New() *code {
32-
if codeInstance == nil {
33-
codeInstance = &code{}
34-
}
35-
return codeInstance
26+
return &code{}
3627
}
3728

3829
// GenDataMatrix is responsible to generate a data matrix byte array.
@@ -76,7 +67,9 @@ func (c *code) GenBar(code string, _ *entity.Cell, prop *props.Barcode) (*entity
7667
return c.getImage(scaledBarCode)
7768
}
7869

79-
func getBarcodeClosure(barcodeType barcode.Type) func(code string) (libBarcode.BarcodeIntCS, error) {
70+
func getBarcodeClosure(
71+
barcodeType barcode.Type,
72+
) func(code string) (libBarcode.BarcodeIntCS, error) {
8073
switch barcodeType {
8174
case barcode.EAN:
8275
return ean.Encode

0 commit comments

Comments
 (0)