feat: unifood base with GET dishes (#1)

Features:
- CLI structure with verbs and resources
- Application config and parameters
- Output formatters
- Initial resource: dishes

Reviewed-on: #1
Co-authored-by: bdoerfchen <git@bissendorf.co>
Co-committed-by: bdoerfchen <git@bissendorf.co>
This commit is contained in:
2025-07-20 17:29:04 +00:00
committed by bissendorf
parent ad082a3f12
commit ec66365b5e
27 changed files with 893 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package jlog
import (
"context"
"log/slog"
)
type ctxKey string
const ctxkeyLogger ctxKey = "jlog:logger"
func FromContext(ctx context.Context) *slog.Logger {
logger, exists := ctx.Value(ctxkeyLogger).(*slog.Logger)
if !exists {
return New(slog.LevelInfo)
}
return logger
}
func ContextWith(ctx context.Context, logger *slog.Logger) context.Context {
return context.WithValue(ctx, ctxkeyLogger, logger)
}

View File

@ -0,0 +1,24 @@
package jlog
import (
"io"
"log/slog"
"math/rand"
"os"
"strconv"
)
func New(level slog.Level) *slog.Logger {
return NewFor(level, os.Stderr)
}
func NewFor(level slog.Level, output io.Writer) *slog.Logger {
return slog.New(slog.NewJSONHandler(output, &slog.HandlerOptions{
// AddSource: true,
Level: level,
})).With(slog.String("traceid", newTraceID()))
}
func newTraceID() string {
return strconv.Itoa(rand.Intn(1000000))
}