After a long-winded post yesterday, here’s a shorter one to breeze through…
Types
… A type may also be specified using a type literal, which composes a type from existing types.
Type = TypeName [ TypeArgs ] | TypeLit | "(" Type ")" . TypeName = identifier | QualifiedIdent . TypeArgs = "[" TypeList [ "," ] "]" . TypeList = Type { "," Type } . TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType | SliceType | MapType | ChannelType .
You’ve already seen these. []byte
, *string
and Struct { Name string; Age int }
are all examples of type literals. There are many more type literals for specific types, which we’ll get to in the coming days.
We’re also skipping over TypeArgs
and TypeList
, which are related to generic types, for the time being.
Quotes from The Go Programming Language Specification, Version of January 19, 2023