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

Add type constraints for Map and Array fields #43

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x
go-version: 1.18.x

- name: Add dependencies
run: |
Expand Down
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 {
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 {
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
Loading