able to get product

This commit is contained in:
Gitea
2023-11-30 00:39:51 +03:00
parent 606b94e35b
commit 414dc87091
19 changed files with 2204 additions and 77 deletions

View File

@ -1,8 +1,11 @@
package config
import (
"bytes"
"log/slog"
"os"
"git.loyso.art/frx/kurious/internal/common/errors"
)
type LogFormat uint8
@ -12,6 +15,19 @@ const (
LogFormatJSON
)
func (f *LogFormat) UnmarshalText(data []byte) error {
switch format := string(bytes.ToLower(data)); format {
case "json":
*f = LogFormatJSON
case "text":
*f = LogFormatText
default:
return errors.NewValidationError("format", "unsupported value "+format)
}
return nil
}
type LogLevel uint8
const (
@ -21,12 +37,29 @@ const (
LogLevelError
)
type LogConfig struct {
Level LogLevel
Format LogFormat
func (lvl *LogLevel) UnmarshalText(data []byte) error {
switch level := string(bytes.ToLower(data)); level {
case "debug", "":
*lvl = LogLevelDebug
case "info":
*lvl = LogLevelInfo
case "warn":
*lvl = LogLevelWarn
case "error":
*lvl = LogLevelError
default:
return errors.NewValidationError("level", "unsupported value "+level)
}
return nil
}
func NewSLogger(config LogConfig) *slog.Logger {
type Log struct {
Level LogLevel `json:"level"`
Format LogFormat `json:"format"`
}
func NewSLogger(config Log) *slog.Logger {
var level slog.Level
switch config.Level {
case LogLevelDebug: