Steel/steel.go
2023-12-19 20:49:11 +01:00

58 lines
918 B
Go

package main
import (
"cimeyclust.com/steel/pkg/cmd"
"cimeyclust.com/steel/pkg/network"
"context"
"fmt"
"os"
"os/signal"
"sync"
"syscall"
)
func main() {
// Channel for stopping the program
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
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()
network.Run(ctx, "0.0.0.0:19132")
}()
// Handles Ctrl+C
go func() {
defer cancel()
select {
case <-sigChan:
cmd.Logger.Info("Received stop command via Ctrl+C")
cancel()
}
}()
// Wait for all components to finish
cmd.Logger.Info("Server started successfully")
wg.Wait()
fmt.Println("Server stopped successfully")
}