go - Pointer within a custom structure -


recently, got exposed following source code "go programming blueprints" book.

type googlegeometry stuct {     *googlelocation `json:"location"` } type googlelocation struct {     lat float64 `json:"lat"`     lng float64 `json:"lng"` } 

what don't understand why googlegeometry structure uses pointer instead of literal, , reason behind such declaration?

i expect below declaration instead of pointer.

type googlegeometry stuct {     gl googlelocation `json:"location"` } 

i suppose because location can null or absent @ all.
such cases can represented pointers. because if literal have default values lat , lng.
please take on example: why pointer?

and value type instead of reference: value types have default values


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -