feat(services): Logging
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user