2.8 Summary
In this chapter, we mainly introduced the 25 Go keywords. Let's review what they are and what they do.
break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var
varandconstare used to define variables and constants.packageandimportare for package use.funcis used to define functions and methods.returnis used to return values in functions or methods.deferis used to define defer functions.gois used to start a new goroutine.selectis used to switch over multiple channels for communication.interfaceis used to define interfaces.structis used to define special customized types.break,case,continue,for,fallthrough,else,if,switch,gotoanddefaultwere introduced in section 2.3.chanis the type of channel for communication among goroutines.typeis used to define customized types.mapis used to define map which is similar to hash tables in other languages.rangeis used for reading data fromslice,mapandchannel.
If you understand how to use these 25 keywords, you've learned a lot of Go already.
Links
- Directory
- Previous section: Concurrency
- Next chapter: Web foundation