mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
refactor: change package names
This commit is contained in:
parent
62578ad5c5
commit
4b77b81689
24 changed files with 167 additions and 155 deletions
24
hcloudimages/contextlogger/context.go
Normal file
24
hcloudimages/contextlogger/context.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package contextlogger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type key int
|
||||
|
||||
var loggerKey key
|
||||
|
||||
func New(ctx context.Context, logger *slog.Logger) context.Context {
|
||||
return context.WithValue(ctx, loggerKey, logger)
|
||||
}
|
||||
|
||||
func From(ctx context.Context) *slog.Logger {
|
||||
if ctxLogger := ctx.Value(loggerKey); ctxLogger != nil {
|
||||
if logger, ok := ctxLogger.(*slog.Logger); ok {
|
||||
return logger
|
||||
}
|
||||
}
|
||||
|
||||
return slog.New(discardHandler{})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue