alt/services/worker/internal/socket/server.go
toki 3ee268816b refactor: update API socket handlers and contract parsers
- Add parser map for contract type resolution
- Update socket handlers with new message routing
- Add parser map tests
- Remove outdated code review and plan docs for G07
2026-05-30 19:14:07 +09:00

39 lines
935 B
Go

package socket
import (
"context"
protoSocket "git.toki-labs.com/toki/proto-socket/go"
"nhooyr.io/websocket"
"git.toki-labs.com/toki/alt/services/worker/internal/config"
workerContracts "git.toki-labs.com/toki/alt/services/worker/internal/contracts"
)
const (
serverName = "alt-worker"
serverVersion = "dev"
defaultAltProtocolVersion = "alt.v1"
)
type Server struct {
wsServer *protoSocket.WsServer
}
func NewServer(cfg config.Config) *Server {
wsServer := protoSocket.NewWsServer(cfg.Host, cfg.Port, cfg.SocketPath, func(conn *websocket.Conn) *protoSocket.WsClient {
return protoSocket.NewWsClient(conn, 30, 10, workerContracts.ParserMap())
})
wsServer.OnClientConnected = registerSessionHandlers
return &Server{
wsServer: wsServer,
}
}
func (s *Server) Start(ctx context.Context) error {
return s.wsServer.Start(ctx)
}
func (s *Server) Stop() error {
return s.wsServer.Stop()
}