|
@@ -4,8 +4,10 @@ import (
|
|
"flag"
|
|
"flag"
|
|
"fmt"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http"
|
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/DeanThompson/ginpprof"
|
|
"github.com/DeanThompson/ginpprof"
|
|
|
|
+ "github.com/denisbrodbeck/machineid"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
"github.com/google/uuid"
|
|
"github.com/gorilla/websocket"
|
|
"github.com/gorilla/websocket"
|
|
@@ -34,7 +36,7 @@ func newApp() *gin.Engine {
|
|
app := gin.Default()
|
|
app := gin.Default()
|
|
ginpprof.Wrap(app)
|
|
ginpprof.Wrap(app)
|
|
|
|
|
|
- id := uuid.NewString()
|
|
|
|
|
|
+ id := serverId()
|
|
srv := &server.Server{
|
|
srv := &server.Server{
|
|
ID: id,
|
|
ID: id,
|
|
Upgrader: websocket.Upgrader{
|
|
Upgrader: websocket.Upgrader{
|
|
@@ -51,3 +53,14 @@ func newApp() *gin.Engine {
|
|
app.GET("/websocket/endpoint", func(ctx *gin.Context) { srv.WebsocketHandler(ctx) })
|
|
app.GET("/websocket/endpoint", func(ctx *gin.Context) { srv.WebsocketHandler(ctx) })
|
|
return app
|
|
return app
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func serverId() string {
|
|
|
|
+ var id string
|
|
|
|
+ id, err := machineid.ID()
|
|
|
|
+ if err != nil {
|
|
|
|
+ id = uuid.NewString()
|
|
|
|
+ } else {
|
|
|
|
+ id = strings.ToLower(id)
|
|
|
|
+ }
|
|
|
|
+ return id
|
|
|
|
+}
|