|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 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)
- }
- }
-
|