tailscale.comtailscale.com/util/mak Index | Files

package mak

import "tailscale.com/util/mak"

Package mak helps make maps. It contains generic helpers to make/assign things, notably to maps, but also slices.

Index

Functions

func NonNilMapForJSON

func NonNilMapForJSON[K comparable, V any, M ~map[K]V](mapPtr *M)

NonNilMapForJSON makes sure that *slicePtr is non-nil so it will won't be omitted from JSON serialization and possibly confuse JavaScript clients expecting it to be present.

func NonNilSliceForJSON

func NonNilSliceForJSON[T any, S ~[]T](slicePtr *S)

NonNilSliceForJSON makes sure that *slicePtr is non-nil so it will won't be omitted from JSON serialization and possibly confuse JavaScript clients expecting it to be present.

func Set

func Set[K comparable, V any, T ~map[K]V](m *T, k K, v V)

Set populates an entry in a map, making the map if necessary.

That is, it assigns (*m)[k] = v, making *m if it was nil.

Source Files

mak.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Last checked
2 days ago

Tools for package owners.