实现远程控制台的通讯机制

This commit is contained in:
dexter
2022-03-12 22:35:17 +08:00
parent 204c37291c
commit c40665125f
7 changed files with 110 additions and 30 deletions

19
io.go
View File

@@ -59,14 +59,7 @@ func (i *IO[C, S]) SetParentCtx(parent context.Context) {
}
func (i *IO[C, S]) OnEvent(event any) {
switch v := event.(type) {
case *Stream:
i.Stream = v
i.StartTime = time.Now()
i.Logger = v.With(zap.String("type", i.Type))
if i.ID != "" {
i.Logger = i.Logger.With(zap.String("ID", i.ID))
}
switch event.(type) {
case SEclose, SEKick:
if i.Closer != nil {
i.Closer.Close()
@@ -76,11 +69,9 @@ func (i *IO[C, S]) OnEvent(event any) {
}
}
}
func (io *IO[C, S]) getID() string {
return io.ID
}
func (io *IO[C, S]) getType() string {
return io.Type
func (io *IO[C, S]) getIO() *IO[C, S] {
return io
}
func (io *IO[C, S]) GetConfig() *C {
@@ -91,8 +82,6 @@ type IIO interface {
IsClosed() bool
OnEvent(any)
Stop()
getID() string
getType() string
}
//Stop 停止订阅或者发布,由订阅者或者发布者调用