v0.0.521 ctxext
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m56s

This commit is contained in:
Mike Schwörer 2024-10-05 01:06:36 +02:00
parent 9f85a243e8
commit 361dca5c85
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 30 additions and 2 deletions

View File

@ -20,6 +20,7 @@ Potentially needs `export GOPRIVATE="gogs.mikescher.com"`
| zipext | Mike | Utility for zip/gzip/tar etc |
| reflectext | Mike | Utility for golang reflection |
| fsext | Mike | Utility for filesytem access |
| ctxext | Mike | Utility for context.Context |
| | | |
| mongoext | Mike | Utility/Helper functions for mongodb (kinda abandoned) |
| cursortoken | Mike | MongoDB cursortoken implementation |

27
ctxext/getter.go Normal file
View File

@ -0,0 +1,27 @@
package ctxext
import "context"
func Value[T any](ctx context.Context, key any) (T, bool) {
v := ctx.Value(key)
if v == nil {
return *new(T), false
}
if tv, ok := v.(T); !ok {
return *new(T), false
} else {
return tv, true
}
}
func ValueOrDefault[T any](ctx context.Context, key any, def T) T {
v := ctx.Value(key)
if v == nil {
return def
}
if tv, ok := v.(T); !ok {
return def
} else {
return tv
}
}

View File

@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.520"
const GoextVersion = "0.0.521"
const GoextVersionTimestamp = "2024-10-05T01:02:25+0200"
const GoextVersionTimestamp = "2024-10-05T01:06:36+0200"