osmlab / yalcha

A Go implementation of openstreetmap-cgimap
4 stars 5 forks source link

use slices vs pointers to slices #8

Closed paulmach closed 6 years ago

paulmach commented 6 years ago

slices in go are weird. they are basically pointer to a sliceHeader, so there is no need for another header. For example:

var s []int
s == nil
len(s) == 0 

actually allocate the header

s := []int{}
s != nil 
len(s) == 0

The former will jsonify to null the latter will jsonify to [] but they will both be excluded by omitempty . That may start to matter when you provide results in json. https://play.golang.org/p/EGl1hcJg9E9

also removed some trailing whitespace.