G

Sintaxe Básica

Go Syntax Guide

Sintaxe e estrutura básica de Go

Sintaxe Básica

Sintaxe e estrutura básica de Go

Go sintaxe básica (go)
        
          package main

import (
    "fmt"
    "math"
)

// Main function - entry point
func main() {
    // Variables
    var name string = "John"
    age := 25  // Short variable declaration
    height := 1.75

    // Constants
    const PI = 3.14159
    const (
        Sunday = iota  // 0
        Monday         // 1
        Tuesday        // 2
    )

    // Arrays
    var numbers [5]int = [5]int{1, 2, 3, 4, 5}
    names := [3]string{"Alice", "Bob", "Charlie"}

    // Slices (dynamic arrays)
    var slice []int
    slice = append(slice, 1, 2, 3)
    dynamicSlice := []int{4, 5, 6}

    // Maps
    person := map[string]interface{}{
        "name":   "John",
        "age":    25,
        "active": true,
    }

    // Printing
    fmt.Println("Hello, World!")
    fmt.Printf("Name: %s, Age: %d\n", name, age)
    fmt.Printf("PI: %.2f\n", PI)
    fmt.Printf("Square root of 16: %.2f\n", math.Sqrt(16))

    // Loops
    for i := 0; i < len(numbers); i++ {
        fmt.Printf("numbers[%d] = %d\n", i, numbers[i])
    }

    // Range loop
    for index, value := range slice {
        fmt.Printf("slice[%d] = %d\n", index, value)
    }

    // Map iteration
    for key, value := range person {
        fmt.Printf("%s: %v\n", key, value)
    }
}
        
      

Explanation

Go usa pacotes para organização. A função main é o ponto de entrada. Go tem arrays, slices e maps como estruturas de dados integradas.

Common Use Cases

  • Programação de sistemas
  • Servidores web
  • Ferramentas CLI
  • Microsserviços

Related Go Syntax

Master Sintaxe Básica in Go

Understanding Sintaxe Básica is fundamental to writing clean and efficient Go code. This comprehensive guide provides you with practical examples and detailed explanations to help you master this important concept.

Whether you're a beginner learning the basics or an experienced developer looking to refresh your knowledge, our examples cover real-world scenarios and best practices for using Sintaxe Básica effectively in your Go projects.

Key Takeaways

  • Programação de sistemas
  • Servidores web
  • Ferramentas CLI