Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 1.42 KB

File metadata and controls

32 lines (26 loc) · 1.42 KB

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
  • var and const are used to define variables and constants.
  • package and import are for package use.
  • func is used to define functions and methods.
  • return is used to return values in functions or methods.
  • defer is used to define defer functions.
  • go is used to start a new goroutine.
  • select is used to switch over multiple channels for communication.
  • interface is used to define interfaces.
  • struct is used to define special customized types.
  • break, case, continue, for, fallthrough, else, if, switch, goto and default were introduced in section 2.3.
  • chan is the type of channel for communication among goroutines.
  • type is used to define customized types.
  • map is used to define map which is similar to hash tables in other languages.
  • range is used for reading data from slice, map and channel.

If you understand how to use these 25 keywords, you've learned a lot of Go already.

Links