Browse Source

config handlers

0x4a52466c696e74 3 months ago
parent
commit
7124c1bc48
2 changed files with 8 additions and 2 deletions
  1. 3 0
      application/app_config.go
  2. 5 2
      application/application.go

+ 3 - 0
application/app_config.go

@@ -1,6 +1,8 @@
 package application
 
 import (
+	"net/http"
+
 	"git.ali33.ru/fcg-xvii/rest"
 	"git.ali33.ru/fcg-xvii/rest/commands"
 )
@@ -30,6 +32,7 @@ type AppConfig struct {
 	Core               any
 	OnSocketConnect    func(rest.IStream)
 	OnSocketDisconnect func(rest.IStream)
+	HttpHandlers       map[string]func(http.ResponseWriter, *http.Request)
 }
 
 func (s *AppConfig) GetCommandsMethod() func(string) (rest.IExecuter, bool) {

+ 5 - 2
application/application.go

@@ -43,7 +43,11 @@ func (s *Application) start(ctx context.Context) (err error) {
 	if s.conf.Http {
 		restServ := rest_http.New(s, s.conf.Core, s.conf.GetHTTPHeaders()())
 		restServ.Prepare(server, s.conf.GetHttpPrefix())
-		//log.Println("http part prepared...")
+		if s.conf.HttpHandlers != nil {
+			for prefix, handler := range s.conf.HttpHandlers {
+				server.HandleFunc(prefix, handler)
+			}
+		}
 	}
 	if s.conf.Websocket {
 		s.chConnect = make(chan rest.IStream)
@@ -51,7 +55,6 @@ func (s *Application) start(ctx context.Context) (err error) {
 		ws.Prepare(server, s.conf.GetWebsocketPrefix())
 		s.Sockets = NewSockets()
 		go s.work()
-		//log.Println("websocket engine prepared...")
 	}
 	if err = server.Listen(time.Second, s.ctx); err != nil {
 		s.cancel()