From a9cb1dc2101660458501e5fc1b06877fcce32cd7 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Tue, 14 Nov 2023 23:49:18 +0100 Subject: [PATCH] Allow passing a byte slice as a string field (#45) --- fieldapi.go | 2 +- fieldapi_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fieldapi.go b/fieldapi.go index 25a6615..351e78d 100644 --- a/fieldapi.go +++ b/fieldapi.go @@ -71,7 +71,7 @@ func Float[T ~float32 | ~float64](key string, val T) Field { } // String constructs a field containing a key and String value. -func String[T ~string](key string, val T) Field { +func String[T ~string | ~[]byte](key string, val T) Field { return Field{Key: key, Type: StringType, String: string(val)} } diff --git a/fieldapi_test.go b/fieldapi_test.go index 465ba5d..0cbfdb3 100644 --- a/fieldapi_test.go +++ b/fieldapi_test.go @@ -68,6 +68,10 @@ func TestFieldString(t *testing.T) { _ = String("string", "foo") type myString string _ = String("string", myString("foo")) + + type myByteSlice string + _ = String("string", []byte{}) + _ = String("string", myByteSlice([]byte{})) } func TestFieldStringer(t *testing.T) {