mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 09:08:57 +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.
60 lines
1.2 KiB
Go
60 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/worker"
|
|
"github.com/giongto35/cloud-game/v2/pkg/thread"
|
|
"github.com/giongto35/cloud-game/v2/pkg/util/logging"
|
|
"github.com/giongto35/cloud-game/v2/pkg/worker"
|
|
"github.com/golang/glog"
|
|
flag "github.com/spf13/pflag"
|
|
)
|
|
|
|
var Version = ""
|
|
|
|
func init() {
|
|
rand.Seed(time.Now().UTC().UnixNano())
|
|
}
|
|
|
|
func run() {
|
|
conf := config.NewConfig()
|
|
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
|
conf.ParseFlags()
|
|
|
|
logging.Init()
|
|
defer logging.Flush()
|
|
|
|
ctx, cancelCtx := context.WithCancel(context.Background())
|
|
|
|
glog.Infof("[worker] version: %v", Version)
|
|
glog.V(4).Info("[worker] Initialization")
|
|
glog.V(4).Infof("[worker] Local configuration %+v", conf)
|
|
wrk := worker.New(ctx, conf)
|
|
wrk.Run()
|
|
|
|
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("[worker] Shutting down [os:%v]", sig)
|
|
done <- struct{}{}
|
|
}()
|
|
|
|
<-done
|
|
wrk.Shutdown()
|
|
cancelCtx()
|
|
}
|
|
|
|
func main() {
|
|
thread.MainWrapMaybe(run)
|
|
}
|