submissions: chatgpt solution
This commit is contained in:
parent
ce59d7c947
commit
3cfcbff253
@ -3,6 +3,7 @@ package cmds
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/auth"
|
"git.itzana.me/strafesnet/go-grpc/auth"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"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")
|
log.WithError(err).Fatal("failed to initialize api server")
|
||||||
}
|
}
|
||||||
|
|
||||||
// idk how else to do this
|
var wg sync.WaitGroup
|
||||||
go http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port-internal")), srv2)
|
wg.Add(2) // We'll wait for two goroutines, one for each server.
|
||||||
return http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv)
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user