/* Copyright (C) 2011-2023 Patrick H. E. Foubet - E2L Ivry Ecole du Logiciel Libre : https://e2li.org/ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see *******************************************************************/ package main import ( "fmt" "math" "net/http" ) type bob int func (b bob) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Salut tout le Monde !")) } type Circle struct { Radius float64 } type Rectangle struct { Width float64 Height float64 } type Shape interface { Area() float64 } func GetArea(s Shape) float64 { return s.Area() } func (c *Circle) Area() float64 { return math.Pi * c.Radius * c.Radius } func (r Rectangle) Area() float64 { return r.Height * r.Width } func main() { circle := Circle{5.0} r1 := Rectangle{4.0, 5.0} r2 := &Rectangle{10.0, 15.0} area := circle.Area() fmt.Println(area) GetArea(&circle) GetArea(r1) GetArea(r2) var x interface{} = 10 fmt.Println(x) str, ok := x.(string) if !ok { fmt.Println("Ne peut pas convertir l'interface x") } fmt.Printf("valeur: %v, Type: %T\n", x, x) x = 1 fmt.Printf("valeur: %v, Type: %T\n", x, x) fmt.Printf("valeur: %v, Type: %T\n", str, str) var y interface{} = "go" switch v := y.(type) { case int: fmt.Printf("Le double de %v vaut %v\n", v, v*2) case string: fmt.Printf("%q a une longueur de %v octets\n", v, len(v)) default: fmt.Printf("Le type de %T est inconnu !\n", v) } }