This commit is contained in:
a.pivkin
2025-07-14 06:14:06 +03:00
parent f7620b40f3
commit cebbf27b3a
11 changed files with 140 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
module main.go
go 1.24.4
+37
View File
@@ -0,0 +1,37 @@
package main
import "fmt"
type Student struct {
name string
age int
}
type Desriber interface {
Describe()
}
func (std Student) Describe(){
fmt.Printf("%s and %d y.o",std.name,std.age)
}
func TypeDescriber(i interface{}){
switch v := i.(type){
case string:
fmt.Println("I am string")
case int:
fmt.Println("I am int")
case Desriber:
fmt.Println("I am describer!")
v.Describe()
default:
fmt.Println("Unknown type but I still work!")
}
}
func main() {
TypeDescriber(9)
std := Student{"Alex", 19}
TypeDescriber(std)
}