go-pattern-examples/creation/04_object_pool/obejct_poo.go
2020-05-05 22:59:18 +08:00

32 lines
436 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package objectpool
import (
"fmt"
"strconv"
)
type doctor struct {
name string
kind int //科室,1内科2外科
}
type pool chan *doctor
func newPool(total int) pool {
p := make(pool, total)
for i := 0; i < total; i++ {
dc := new(doctor)
dc.name = "doctor: " + strconv.Itoa(i)
p <- dc
}
return p
}
//surgery
func (d doctor) surgery(someone string) {
fmt.Println("doctor:", d.name, "do surgery for", someone)
}