Compare commits
No commits in common. "acadb8457fb21738f02c7d12a2b10c678b0103ca" and "a64a2dc434b37cc09ab45eccca01c84d0f17bd6b" have entirely different histories.
acadb8457f
...
a64a2dc434
@ -1,12 +0,0 @@
|
|||||||
package sensor
|
|
||||||
|
|
||||||
type Sensor interface {
|
|
||||||
Add()
|
|
||||||
Delete()
|
|
||||||
Update()
|
|
||||||
Search()
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddSensor(s Sensor) {
|
|
||||||
s.Add()
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package sensorimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"golanglearn/interface/example1/sensor"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Ftp struct {
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Ftp) Add() {
|
|
||||||
fmt.Println("ftp sensor", f.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Ftp) Delete() {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Ftp) Update() {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Ftp) Search() {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewFtp(name string) sensor.Sensor {
|
|
||||||
return &Ftp{Name: name}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package sensorimpl
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"golanglearn/interface/example1/sensor"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Rtsp struct {
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rtsp) Add() {
|
|
||||||
fmt.Println("add sensor", r.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rtsp) Delete() {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rtsp) Update() {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rtsp) Search() {
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRtsp(name string) sensor.Sensor {
|
|
||||||
return &Rtsp{Name: name}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"golanglearn/interface/example1/sensor"
|
|
||||||
"golanglearn/interface/example1/sensor/sensorimpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rtsp1 := sensorimpl.NewRtsp("xxx")
|
|
||||||
sensor.AddSensor(rtsp1)
|
|
||||||
ftp1 := sensorimpl.NewFtp("ftp")
|
|
||||||
sensor.AddSensor(ftp1)
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
限制并发数量的用法
|
|
||||||
*/
|
|
||||||
func main() {
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
// 最多允许的并发数量
|
|
||||||
limit := make(chan struct{}, 20)
|
|
||||||
for i := 0; i < 100; i++ {
|
|
||||||
wg.Add(1)
|
|
||||||
limit <- struct{}{}
|
|
||||||
go func(num int) {
|
|
||||||
defer func() {
|
|
||||||
<-limit
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
dosth(num)
|
|
||||||
}(i)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
func dosth(i int) {
|
|
||||||
fmt.Println("do sth-->", strconv.Itoa(i))
|
|
||||||
// 模拟耗时1s
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
> 用waitgroup限制并发数量的用法
|
|
Loading…
Reference in New Issue
Block a user