Go接口实现是不依赖Go接口的定义--duck type 类似就可以
package _interface
import "testing"
type code string
type Programmer interface {
WirteHelloWolrd() code
}
type GoProgrammer struct {
}
func (g *GoProgrammer) WirteHelloWolrd() code{
return "fmt.Println(\"Hello wolrd\")"
}
func TestClient(t *testing.T){
var p Programmer
p = new(GoProgrammer)
t.Log(p.WirteHelloWolrd())
}
类型简化
package customer_type
import (
"fmt"
"testing"
"time"
)
type Innop = func(op int) int
func timeSpend(inner Innop) Innop{
return func(op int) int{
start := time.Now()
end := inner(op)
fmt.Println("time spent:",time.Since(start).Seconds())
return end
}
}
func slowFunc(op int) int {
time.Sleep(time.Second * 10)
return op
}
func TestFunc(t *testing.T){
tssf := timeSpend(slowFunc)
tssf(10)
}