|
@@ -2,8 +2,6 @@ package application
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
- "log"
|
|
|
|
- "sync/atomic"
|
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"git.ali33.ru/fcg-xvii/rest"
|
|
"git.ali33.ru/fcg-xvii/rest"
|
|
@@ -13,7 +11,8 @@ import (
|
|
|
|
|
|
func New(appConf *AppConfig, swaggerConf *SwaggerConf, ctx context.Context) rest.IApplication {
|
|
func New(appConf *AppConfig, swaggerConf *SwaggerConf, ctx context.Context) rest.IApplication {
|
|
app := &Application{
|
|
app := &Application{
|
|
- conf: appConf,
|
|
|
|
|
|
+ conf: appConf,
|
|
|
|
+ Sockets: NewSockets(),
|
|
}
|
|
}
|
|
if swaggerConf != nil && swaggerConf.Enabled {
|
|
if swaggerConf != nil && swaggerConf.Enabled {
|
|
app.swagger = NewSwagger(swaggerConf)
|
|
app.swagger = NewSwagger(swaggerConf)
|
|
@@ -24,6 +23,7 @@ func New(appConf *AppConfig, swaggerConf *SwaggerConf, ctx context.Context) rest
|
|
}
|
|
}
|
|
|
|
|
|
type Application struct {
|
|
type Application struct {
|
|
|
|
+ *Sockets
|
|
conf *AppConfig
|
|
conf *AppConfig
|
|
swagger *Swagger
|
|
swagger *Swagger
|
|
//core any
|
|
//core any
|
|
@@ -62,28 +62,6 @@ func (s *Application) Stop() {
|
|
s.cancel()
|
|
s.cancel()
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *Application) work() {
|
|
|
|
- var counter atomic.Int32
|
|
|
|
- for {
|
|
|
|
- select {
|
|
|
|
- case <-s.ctx.Done():
|
|
|
|
- return
|
|
|
|
- case stream := <-s.chConnect:
|
|
|
|
- log.Println("CONNECT-------", counter.Add(1))
|
|
|
|
- if s.conf.OnSocketConnect != nil {
|
|
|
|
- s.conf.OnSocketConnect(stream)
|
|
|
|
- }
|
|
|
|
- go func(rStream rest.IStream) {
|
|
|
|
- <-rStream.Context().Done()
|
|
|
|
- log.Println("DISCONNECT-------", counter.Add(-1))
|
|
|
|
- if s.conf.OnSocketDisconnect != nil {
|
|
|
|
- s.conf.OnSocketDisconnect(rStream)
|
|
|
|
- }
|
|
|
|
- }(stream)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func (s *Application) Executer(r rest.IRequestIn) (rest.IExecuter, bool) {
|
|
func (s *Application) Executer(r rest.IRequestIn) (rest.IExecuter, bool) {
|
|
method := s.conf.GetCommandsMethod()
|
|
method := s.conf.GetCommandsMethod()
|
|
if command, check := method(r.RCommand()); check {
|
|
if command, check := method(r.RCommand()); check {
|
|
@@ -91,7 +69,3 @@ func (s *Application) Executer(r rest.IRequestIn) (rest.IExecuter, bool) {
|
|
}
|
|
}
|
|
return nil, false
|
|
return nil, false
|
|
}
|
|
}
|
|
-
|
|
|
|
-func (s *Application) Connect() chan<- rest.IStream {
|
|
|
|
- return s.chConnect
|
|
|
|
-}
|
|
|