diff --git a/app.go b/app.go index b05a053a..8bf4434b 100644 --- a/app.go +++ b/app.go @@ -94,12 +94,7 @@ type App struct { var ( app = &App{ - server: &cluster.Server{ - ID: uuid.New().String(), - Type: "game", - Metadata: map[string]string{}, - Frontend: true, - }, + server: cluster.NewServer(uuid.New().String(), "game", true, map[string]string{}), debug: false, startAt: time.Now(), dieChan: make(chan bool), diff --git a/cluster/server.go b/cluster/server.go index 9ebc2056..7d3cfbd6 100644 --- a/cluster/server.go +++ b/cluster/server.go @@ -22,6 +22,7 @@ package cluster import ( "encoding/json" + "os" "github.com/topfreegames/pitaya/logger" ) @@ -32,11 +33,16 @@ type Server struct { Type string `json:"type"` Metadata map[string]string `json:"metadata"` Frontend bool `json:"frontend"` + Hostname string `json:"hostname"` } // NewServer ctor func NewServer(id, serverType string, frontend bool, metadata ...map[string]string) *Server { d := make(map[string]string) + h, err := os.Hostname() + if err != nil { + logger.Log.Errorf("failed to get hostname: %s", err.Error()) + } if len(metadata) > 0 { d = metadata[0] } @@ -45,6 +51,7 @@ func NewServer(id, serverType string, frontend bool, metadata ...map[string]stri Type: serverType, Metadata: d, Frontend: frontend, + Hostname: h, } } diff --git a/cluster/server_test.go b/cluster/server_test.go index aba943a8..96d054ee 100644 --- a/cluster/server_test.go +++ b/cluster/server_test.go @@ -47,6 +47,7 @@ func TestNewServer(t *testing.T) { assert.Equal(t, table.id, s.ID) assert.Equal(t, table.metadata, s.Metadata) assert.Equal(t, table.frontend, s.Frontend) + assert.NotNil(t, s.Hostname) }) } }