📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 5

Retour
Définir un struct
Facile
type Personne struct {
    Nom string
    Age int
}
Définir une interface
Intermédiaire
type Forme interface {
    aire() float64
}
Définir une méthode sur un struct
Intermédiaire
func (p Personne) Saluer() {
    fmt.Printf("Bonjour, je m'appelle %s\n", p.Nom)
}
Implémenter une interface
Avancé
type Cercle struct { rayon float64 }

func (c Cercle) aire() float64 {
    return math.Pi * c.rayon * c.rayon
}
Instancier un struct
Facile
p := Personne{Nom: "Alice", Age: 30}