Golang Patterns

From Adam Colton
Revision as of 15:14, 25 October 2016 by Adamcolton (talk | contribs) (Created page with "== Privacy == === Readonly package var === type priv struct{...} var Pub = priv{...} Pub can only be set internally because priv cannot be created. Useful in cases where...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Privacy

Readonly package var

 type priv struct{...}
 var Pub = priv{...}

Pub can only be set internally because priv cannot be created. Useful in cases where you would use a const, but that's not possible with a struct.

Structs

Literal as Key

 type Coord struct{
   X,Y int
 }
 grid := make(map[Coord]string)

By using the literal of Coord, the values can be compared directly.