feat(services): Logging
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
2024-12-17 16:23:52 +01:00
parent 4d57cf827d
commit 11ea0858bb
5 changed files with 72 additions and 13 deletions

View File

@@ -7,6 +7,8 @@ import (
"fmt"
"html/template"
"strings"
"go.uber.org/zap"
)
type Templater interface {
@@ -17,6 +19,7 @@ type Templater interface {
type DefaultTemplater struct {
BarcodeService BarcodeService
StaticService StaticService
Logger *zap.SugaredLogger
}
func idToEan13(id string, prefix string) (string, error) {
@@ -48,10 +51,13 @@ func (t *DefaultTemplater) GenerateBarcode(code string, format string, prefix st
}
func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
logger := t.Logger.Named("SelectSponsorImage")
sponsors, err := t.StaticService.ListFilesInStaticSubFolder("images/sponsors")
if err != nil {
logger.Errorw("Failed to list sponsors", "error", err)
return "", err
}
logger.Debugw("Selected sponsor", "sponsors", sponsors, "id", id, "selected", sponsors[id%len(sponsors)])
return t.StaticService.GetImage("sponsors/" + strings.TrimSuffix(sponsors[id%len(sponsors)], ".base64")), nil
}