Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a byte slice as a string field #45

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fieldapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}

Expand Down
4 changes: 4 additions & 0 deletions fieldapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading