Skip to content

Commit

Permalink
Add hostname to server type (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielerzinger authored and cscatolini committed Oct 3, 2018
1 parent 33c6262 commit 08d1d52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 1 addition & 6 deletions app.go
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions cluster/server.go
Expand Up @@ -22,6 +22,7 @@ package cluster

import (
"encoding/json"
"os"

"github.com/topfreegames/pitaya/logger"
)
Expand All @@ -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]
}
Expand All @@ -45,6 +51,7 @@ func NewServer(id, serverType string, frontend bool, metadata ...map[string]stri
Type: serverType,
Metadata: d,
Frontend: frontend,
Hostname: h,
}
}

Expand Down
1 change: 1 addition & 0 deletions cluster/server_test.go
Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit 08d1d52

Please sign in to comment.