Add MapOmit, Context Parse/Serialize

This commit is contained in:
George Suntres
2026-04-23 13:17:48 -04:00
parent 1e9e43668f
commit 0ce3f3b5eb
4 changed files with 43 additions and 16 deletions

26
context.go Normal file
View File

@@ -0,0 +1,26 @@
package commons
import "context"
func ContextSerialize(ctx context.Context, fields []string) map[string]any {
m := map[string]any{}
for _, name := range fields {
vAny := ctx.Value(name)
v, ok := vAny.(string)
if ok {
m[name] = v
}
}
return m
}
func ContextFromMap(m map[string]any) context.Context {
ctx := context.Background()
for k, v := range m {
ctx = context.WithValue(ctx, k, v)
}
return ctx
}