mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-24 02:27:32 +00:00
Both worker and coordinator display version number in the console during startup. Coordinator displays its version number in the top right corner of the index.html page.
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
goflag "flag"
|
|
"math/rand"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
config "github.com/giongto35/cloud-game/v2/pkg/config/coordinator"
|
|
"github.com/giongto35/cloud-game/v2/pkg/coordinator"
|
|
"github.com/giongto35/cloud-game/v2/pkg/util/logging"
|
|
"github.com/golang/glog"
|
|
flag "github.com/spf13/pflag"
|
|
)
|
|
|
|
var Version = ""
|
|
|
|
func main() {
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
|
|
conf := config.NewConfig()
|
|
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
|
conf.ParseFlags()
|
|
|
|
logging.Init()
|
|
defer logging.Flush()
|
|
|
|
ctx, cancelCtx := context.WithCancel(context.Background())
|
|
|
|
glog.Infof("[coordinator] version: %v", Version)
|
|
glog.Infof("Initializing coordinator server")
|
|
glog.V(4).Infof("Coordinator configs %v", conf)
|
|
o := coordinator.New(ctx, conf)
|
|
if err := o.Run(); err != nil {
|
|
glog.Errorf("Failed to run coordinator server, reason %v", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
signals := make(chan os.Signal, 1)
|
|
done := make(chan struct{}, 1)
|
|
|
|
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
sig := <-signals
|
|
glog.V(4).Infof("[coordinator] Shutting down [os:%v]", sig)
|
|
done <- struct{}{}
|
|
}()
|
|
|
|
<-done
|
|
o.Shutdown()
|
|
cancelCtx()
|
|
}
|