submissions: chatgpt solution

This commit is contained in:
Quaternions 2024-12-15 01:47:43 -08:00
parent ce59d7c947
commit 3cfcbff253

View File

@ -3,6 +3,7 @@ package cmds
import (
"fmt"
"net/http"
"sync"
"git.itzana.me/strafesnet/go-grpc/auth"
"git.itzana.me/strafesnet/maps-service/pkg/api"
@ -138,7 +139,30 @@ func serve(ctx *cli.Context) error {
log.WithError(err).Fatal("failed to initialize api server")
}
// idk how else to do this
go http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port-internal")), srv2)
return http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv)
var wg sync.WaitGroup
wg.Add(2) // We'll wait for two goroutines, one for each server.
// First server
go func() {
defer wg.Done()
err := http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port-internal")), srv2)
if err != nil {
log.Printf("Internal server error: %v", err)
}
}()
// Second server
go func() {
defer wg.Done()
err := http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv)
if err != nil {
log.Printf("External server error: %v", err)
}
}()
// Wait for both servers to finish.
wg.Wait()
log.Println("Both servers have stopped.")
return nil
}