Skip to content

Commit

Permalink
Add type contrains for Map and Array fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei committed Oct 26, 2023
1 parent e0a61b2 commit b0eba55
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions fieldapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func Millis(key string, val int64) Field {
}

// Array constructs a field containing a key and array value.
func Array(key string, val interface{}) Field {
func Array[S ~[]E, E any](key string, val S) Field {

Check failure on line 103 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

missing function body

Check failure on line 103 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected [, expecting (

Check failure on line 103 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

missing function body

Check failure on line 103 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected [, expecting (

Check failure on line 103 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

missing function body

Check failure on line 103 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected [, expecting (
return Field{Key: key, Type: ArrayType, Interface: val}
}

// Map constructs a field containing a key and map value.
func Map(key string, val interface{}) Field {
func Map[M ~map[K]V, K comparable, V any](key string, val M) Field {

Check failure on line 108 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

missing function body

Check failure on line 108 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected [, expecting (

Check failure on line 108 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

missing function body

Check failure on line 108 in fieldapi.go

View workflow job for this annotation

GitHub Actions / test

syntax error: unexpected [, expecting (
return Field{Key: key, Type: MapType, Interface: val}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mattermost/logr/v2

go 1.17
go 1.18

require (
github.com/francoispqt/gojay v1.2.13
Expand Down

0 comments on commit b0eba55

Please sign in to comment.