Home >Backend Development >Golang >Discovering Go: Chapter First Steps in the Language
Starting my journey with the Go language, I decided to share my learnings. This is the first in a series of introductory Go tutorials.
Go is a compiled language. When executing the compilation command, the source code (files with extension .go
) is translated into machine language.
For direct execution, the run
command is ideal for quick tests. For programs with continuous use or in production, the command build
generates an executable binary.
All Go code is organized into packages, similar to libraries or modules in other languages (although different from the package structure in Java, for example). A package consists of one or more files .go
in the same directory.
Each file starts with the package declaration (e.g. package main
).
Then the imports
, using the import
keyword, declares the required external packages. Just like in other languages, we use packages for specific tasks. The Go compiler is strict, preventing compilation if there are missing or unnecessary imports
, ensuring only the essentials are included.
Functions are declared with func
, followed by the name and parameters (if any): func nomeDaFuncao(parâmetros) { ... }
.
Go generally dispenses with semicolons at the end of lines, except when two or more instructions are on the same line.
Line breaks indicate the end of an instruction. The opening braces {
of a function must be on the same line as the declaration: func main() {
.
<code class="language-go">package main import "fmt" func main() { fmt.Println("Hello, World") }</code>
Did you like the content? Leave your comment or share your experience with Go! In the next chapters, we will explore more examples to consolidate learning.
The above is the detailed content of Discovering Go: Chapter First Steps in the Language. For more information, please follow other related articles on the PHP Chinese website!