Go je jednoduchý, rychlý, kompilovaný jazyk od Googlu. Ideální pro CLI nástroje, API servery, mikroservices.
Hello World a structs¶
package main import “fmt” type User struct { Name string Email string Age int } func (u User) Greet() string { return fmt.Sprintf(“Hello, %s!”, u.Name) } func main() { user := User{Name: “Jan”, Email: “[email protected]”, Age: 30} fmt.Println(user.Greet()) }
Error handling¶
func divide(a, b float64) (float64, error) { if b == 0 { return 0, fmt.Errorf(“division by zero”) } return a / b, nil } result, err := divide(10, 0) if err != nil { log.Fatal(err) }
HTTP server¶
package main import ( “encoding/json” “net/http” ) func main() { http.HandleFunc(“/api/hello”, func(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(map[string]string{“message”: “Hello!”}) }) http.ListenAndServe(“:8080”, nil) }
Klíčový takeaway¶
Go je jednoduchý — naučíte se za týden. Error handling explicitní (if err != nil). Skvělý pro backend a CLI.