Steel/steel.go

58 lines
918 B
Go
Raw Normal View History

package main
import (
"cimeyclust.com/steel/pkg/cmd"
2023-12-19 20:49:11 +01:00
"cimeyclust.com/steel/pkg/network"
"context"
2023-12-17 01:03:49 +01:00
"fmt"
"os"
"os/signal"
"sync"
2023-12-17 01:03:49 +01:00
"syscall"
)
func main() {
// Channel for stopping the program
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
2023-12-17 01:03:49 +01:00
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
var wg sync.WaitGroup
// Start the console handler
wg.Add(1)
go func() {
defer wg.Done()
defer cancel()
cmd.Run(ctx)
}()
// Start the network server
wg.Add(1)
go func() {
defer wg.Done()
2023-12-19 20:49:11 +01:00
network.Run(ctx, "0.0.0.0:19132")
}()
2023-12-17 01:03:49 +01:00
// Handles Ctrl+C
go func() {
defer cancel()
select {
case <-sigChan:
cmd.Logger.Info("Received stop command via Ctrl+C")
cancel()
}
}()
2023-12-16 20:52:05 +01:00
// Wait for all components to finish
2023-12-17 01:03:49 +01:00
cmd.Logger.Info("Server started successfully")
wg.Wait()
2023-12-17 01:03:49 +01:00
fmt.Println("Server stopped successfully")
}