From b6e3be945680d017874967ae72ef86ee4235dcc2 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Thu, 18 Jul 2024 16:15:08 -0700 Subject: Add initial HTTP API endpoints --- hotline/server.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'hotline') diff --git a/hotline/server.go b/hotline/server.go index 58a9209..cfdb6b3 100644 --- a/hotline/server.go +++ b/hotline/server.go @@ -13,6 +13,7 @@ import ( "log" "log/slog" "net" + "os" "strings" "sync" "time" @@ -586,3 +587,18 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro } return nil } + +func (s *Server) SendAll(t TranType, fields ...Field) { + for _, c := range s.ClientMgr.List() { + s.outbox <- NewTransaction(t, c.ID, fields...) + } +} + +func (s *Server) Shutdown(msg []byte) { + s.Logger.Info("Shutdown signal received") + s.SendAll(TranDisconnectMsg, NewField(FieldData, msg)) + + time.Sleep(3 * time.Second) + + os.Exit(0) +} -- cgit