What Is the Difference Between new and make in Go

Use new for zeroed pointers and make for initialized slices, maps, and channels.

Use new to allocate zeroed memory for a single value and make to initialize slices, maps, and channels. new returns a pointer to the zero value, while make returns the initialized type itself.

// new returns a pointer to a zeroed int
i := new(int) 

// make returns an initialized slice
s := make([]int, 5)

// make returns an initialized map
m := make(map[string]int)

// make returns an initialized channel
ch := make(chan int)