util/mak: deprecate NonNil, add type-safe NonNilSliceForJSON, NonNilMapForJSON

And put the rationale in the name too to save the callers the need for a comment.

Change-Id: I090f51b749a5a0641897ee89a8fb2e2080c8b782
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-09-10 12:11:59 -07:00
committed by Maisem Ali
parent e7376aca25
commit f3ce1e2536
3 changed files with 42 additions and 33 deletions

View File

@ -69,3 +69,21 @@ func TestNonNil(t *testing.T) {
t.Error("map still nil")
}
}
func TestNonNilMapForJSON(t *testing.T) {
type M map[string]int
var m M
NonNilMapForJSON(&m)
if m == nil {
t.Fatal("still nil")
}
}
func TestNonNilSliceForJSON(t *testing.T) {
type S []int
var s S
NonNilSliceForJSON(&s)
if s == nil {
t.Fatal("still nil")
}
}