From 34c66fd26a611dca7d0f793d2f8e801727ae8e52 Mon Sep 17 00:00:00 2001 From: Danilo Jakob Date: Tue, 19 Nov 2024 22:11:12 +0100 Subject: [PATCH] feat(server): updated module name to adhere to golang standard --- server/cmd/{triffgonix => }/main.go | 5 ++-- server/cmd/{triffgonix => }/main_test.go | 0 server/go.mod | 4 ++-- server/internal/{triffgonix => }/api/api.go | 24 +++++++++---------- .../internal/{triffgonix => }/api/api_test.go | 4 ++-- .../internal/{triffgonix => }/api/dto/data.go | 4 ++-- .../{triffgonix => }/api/socket/data.go | 0 .../{triffgonix => }/api/socket/hub.go | 6 ++--- .../{triffgonix => }/api/socket/hub_test.go | 2 +- .../{triffgonix => }/dart/engine/engine.go | 4 ++-- .../dart/engine/engine_test.go | 2 +- .../dart/engine/x01/x01engine.go | 7 +++--- .../dart/engine/x01/x01engine_test.go | 4 ++-- .../{triffgonix => }/database/database.go | 2 +- .../database/database_test.go | 2 +- .../internal/{triffgonix => }/domain/data.go | 4 +++- .../internal/{triffgonix => }/models/model.go | 0 17 files changed, 38 insertions(+), 36 deletions(-) rename server/cmd/{triffgonix => }/main.go (89%) rename server/cmd/{triffgonix => }/main_test.go (100%) rename server/internal/{triffgonix => }/api/api.go (82%) rename server/internal/{triffgonix => }/api/api_test.go (87%) rename server/internal/{triffgonix => }/api/dto/data.go (91%) rename server/internal/{triffgonix => }/api/socket/data.go (100%) rename server/internal/{triffgonix => }/api/socket/hub.go (94%) rename server/internal/{triffgonix => }/api/socket/hub_test.go (96%) rename server/internal/{triffgonix => }/dart/engine/engine.go (97%) rename server/internal/{triffgonix => }/dart/engine/engine_test.go (98%) rename server/internal/{triffgonix => }/dart/engine/x01/x01engine.go (94%) rename server/internal/{triffgonix => }/dart/engine/x01/x01engine_test.go (99%) rename server/internal/{triffgonix => }/database/database.go (94%) rename server/internal/{triffgonix => }/database/database_test.go (91%) rename server/internal/{triffgonix => }/domain/data.go (96%) rename server/internal/{triffgonix => }/models/model.go (100%) diff --git a/server/cmd/triffgonix/main.go b/server/cmd/main.go similarity index 89% rename from server/cmd/triffgonix/main.go rename to server/cmd/main.go index 3fecf79..31d66f8 100644 --- a/server/cmd/triffgonix/main.go +++ b/server/cmd/main.go @@ -1,9 +1,8 @@ package main import ( - "server/internal/triffgonix/api" - "server/internal/triffgonix/database" - + "github.com/DaniloMurer/triffgonix/server/internal/api" + "github.com/DaniloMurer/triffgonix/server/internal/database" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) diff --git a/server/cmd/triffgonix/main_test.go b/server/cmd/main_test.go similarity index 100% rename from server/cmd/triffgonix/main_test.go rename to server/cmd/main_test.go diff --git a/server/go.mod b/server/go.mod index acdb89a..baffcc4 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,4 +1,4 @@ -module server +module github.com/DaniloMurer/triffgonix/server go 1.23.0 @@ -9,6 +9,7 @@ require github.com/gin-contrib/cors v1.7.2 require gorm.io/gorm v1.25.11 require ( + github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.3 github.com/stretchr/testify v1.9.0 gorm.io/driver/sqlite v1.5.6 @@ -26,7 +27,6 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect diff --git a/server/internal/triffgonix/api/api.go b/server/internal/api/api.go similarity index 82% rename from server/internal/triffgonix/api/api.go rename to server/internal/api/api.go index 2406bf1..bd3b7bc 100644 --- a/server/internal/triffgonix/api/api.go +++ b/server/internal/api/api.go @@ -1,14 +1,14 @@ package api import ( + "github.com/DaniloMurer/triffgonix/server/internal/api/dto" + socket2 "github.com/DaniloMurer/triffgonix/server/internal/api/socket" + "github.com/DaniloMurer/triffgonix/server/internal/dart/engine" + "github.com/DaniloMurer/triffgonix/server/internal/dart/engine/x01" + "github.com/DaniloMurer/triffgonix/server/internal/database" + "github.com/DaniloMurer/triffgonix/server/internal/models" + "github.com/DaniloMurer/triffgonix/server/pkg/logging" "net/http" - "server/internal/triffgonix/api/dto" - "server/internal/triffgonix/api/socket" - "server/internal/triffgonix/dart/engine" - "server/internal/triffgonix/dart/engine/x01" - "server/internal/triffgonix/database" - "server/internal/triffgonix/models" - "server/pkg/logging" "strconv" "github.com/gin-gonic/gin" @@ -17,7 +17,7 @@ import ( var ( upgrader = websocket.Upgrader{} - hubs = map[string]socket.Hub{} + hubs = map[string]socket2.Hub{} generalConnections []*websocket.Conn ) @@ -36,14 +36,14 @@ func HandleDartWebSocket(c *gin.Context) { } gameId := c.Param("gameId") // get message from socket - var message socket.IncomingMessage + var message socket2.IncomingMessage err = conn.ReadJSON(&message) if err != nil { logger.Error("error while reading from socket connection: %v", err) return } switch *message.Type { - case socket.Handshake: + case socket2.Handshake: hub, exists := hubs[gameId] if exists { hub.RegisterNewClient(conn) @@ -120,7 +120,7 @@ func CreateGame(c *gin.Context) { Players: &players, Engine: x01.New(newGame.StartingScore), } - newHub := socket.Hub{Id: savedGame.Id, Clients: map[*socket.Client]bool{}, Game: game} + newHub := socket2.Hub{Id: savedGame.Id, Clients: map[*socket2.Client]bool{}, Game: game} hubs[strconv.FormatUint(uint64(savedGame.Id), 10)] = newHub broadcastNewGame(savedGame) c.JSON(http.StatusCreated, &savedGame) @@ -134,7 +134,7 @@ func GetGames(c *gin.Context) { func broadcastNewGame(newGame *models.Game) { game := dto.Game{} game.FromEntity(newGame) - message := socket.OutgoingMessage{Type: socket.NewGame, Content: game} + message := socket2.OutgoingMessage{Type: socket2.NewGame, Content: game} for _, conn := range generalConnections { err := conn.WriteJSON(message) if err != nil { diff --git a/server/internal/triffgonix/api/api_test.go b/server/internal/api/api_test.go similarity index 87% rename from server/internal/triffgonix/api/api_test.go rename to server/internal/api/api_test.go index ccf4f59..d2e0a34 100644 --- a/server/internal/triffgonix/api/api_test.go +++ b/server/internal/api/api_test.go @@ -1,10 +1,10 @@ package api import ( + "github.com/DaniloMurer/triffgonix/server/internal/database" + "github.com/DaniloMurer/triffgonix/server/internal/models" "github.com/google/uuid" "net/http/httptest" - "server/internal/triffgonix/database" - "server/internal/triffgonix/models" "testing" "github.com/gin-gonic/gin" diff --git a/server/internal/triffgonix/api/dto/data.go b/server/internal/api/dto/data.go similarity index 91% rename from server/internal/triffgonix/api/dto/data.go rename to server/internal/api/dto/data.go index 521f755..6d0fabb 100644 --- a/server/internal/triffgonix/api/dto/data.go +++ b/server/internal/api/dto/data.go @@ -1,8 +1,8 @@ package dto import ( - "server/internal/triffgonix/domain" - "server/internal/triffgonix/models" + "github.com/DaniloMurer/triffgonix/server/internal/domain" + "github.com/DaniloMurer/triffgonix/server/internal/models" ) type Players struct { diff --git a/server/internal/triffgonix/api/socket/data.go b/server/internal/api/socket/data.go similarity index 100% rename from server/internal/triffgonix/api/socket/data.go rename to server/internal/api/socket/data.go diff --git a/server/internal/triffgonix/api/socket/hub.go b/server/internal/api/socket/hub.go similarity index 94% rename from server/internal/triffgonix/api/socket/hub.go rename to server/internal/api/socket/hub.go index df9d99d..f5d82de 100644 --- a/server/internal/triffgonix/api/socket/hub.go +++ b/server/internal/api/socket/hub.go @@ -1,10 +1,10 @@ package socket import ( + "github.com/DaniloMurer/triffgonix/server/internal/dart/engine" + "github.com/DaniloMurer/triffgonix/server/internal/domain" + "github.com/DaniloMurer/triffgonix/server/pkg/logging" "github.com/gorilla/websocket" - "server/internal/triffgonix/dart/engine" - "server/internal/triffgonix/domain" - "server/pkg/logging" ) var logger = logging.NewLogger() diff --git a/server/internal/triffgonix/api/socket/hub_test.go b/server/internal/api/socket/hub_test.go similarity index 96% rename from server/internal/triffgonix/api/socket/hub_test.go rename to server/internal/api/socket/hub_test.go index ae12f7a..31690bb 100644 --- a/server/internal/triffgonix/api/socket/hub_test.go +++ b/server/internal/api/socket/hub_test.go @@ -1,7 +1,7 @@ package socket import ( - "server/pkg/logging" + "github.com/DaniloMurer/triffgonix/server/pkg/logging" "testing" ) diff --git a/server/internal/triffgonix/dart/engine/engine.go b/server/internal/dart/engine/engine.go similarity index 97% rename from server/internal/triffgonix/dart/engine/engine.go rename to server/internal/dart/engine/engine.go index 493970d..9db86be 100644 --- a/server/internal/triffgonix/dart/engine/engine.go +++ b/server/internal/dart/engine/engine.go @@ -1,8 +1,8 @@ package engine import ( - "server/internal/triffgonix/api/dto" - "server/internal/triffgonix/domain" + "github.com/DaniloMurer/triffgonix/server/internal/api/dto" + "github.com/DaniloMurer/triffgonix/server/internal/domain" ) type Engine interface { diff --git a/server/internal/triffgonix/dart/engine/engine_test.go b/server/internal/dart/engine/engine_test.go similarity index 98% rename from server/internal/triffgonix/dart/engine/engine_test.go rename to server/internal/dart/engine/engine_test.go index 3791185..68bf076 100644 --- a/server/internal/triffgonix/dart/engine/engine_test.go +++ b/server/internal/dart/engine/engine_test.go @@ -1,7 +1,7 @@ package engine import ( - "server/internal/triffgonix/domain" + "github.com/DaniloMurer/triffgonix/server/internal/domain" "testing" ) diff --git a/server/internal/triffgonix/dart/engine/x01/x01engine.go b/server/internal/dart/engine/x01/x01engine.go similarity index 94% rename from server/internal/triffgonix/dart/engine/x01/x01engine.go rename to server/internal/dart/engine/x01/x01engine.go index 96a6327..358b6ba 100644 --- a/server/internal/triffgonix/dart/engine/x01/x01engine.go +++ b/server/internal/dart/engine/x01/x01engine.go @@ -1,9 +1,10 @@ +// Package x01 is the implementation of the X01 dart game mode package x01 import ( - "server/internal/triffgonix/dart/engine" - "server/internal/triffgonix/domain" - "server/pkg/logging" + "github.com/DaniloMurer/triffgonix/server/internal/dart/engine" + "github.com/DaniloMurer/triffgonix/server/internal/domain" + "github.com/DaniloMurer/triffgonix/server/pkg/logging" ) var logger = logging.NewLogger() diff --git a/server/internal/triffgonix/dart/engine/x01/x01engine_test.go b/server/internal/dart/engine/x01/x01engine_test.go similarity index 99% rename from server/internal/triffgonix/dart/engine/x01/x01engine_test.go rename to server/internal/dart/engine/x01/x01engine_test.go index 18e087e..1c9d0d7 100644 --- a/server/internal/triffgonix/dart/engine/x01/x01engine_test.go +++ b/server/internal/dart/engine/x01/x01engine_test.go @@ -2,8 +2,8 @@ package x01 import ( "fmt" - "server/internal/triffgonix/dart/engine" - "server/internal/triffgonix/domain" + "github.com/DaniloMurer/triffgonix/server/internal/dart/engine" + "github.com/DaniloMurer/triffgonix/server/internal/domain" "testing" ) diff --git a/server/internal/triffgonix/database/database.go b/server/internal/database/database.go similarity index 94% rename from server/internal/triffgonix/database/database.go rename to server/internal/database/database.go index d713f0d..99a9ba0 100644 --- a/server/internal/triffgonix/database/database.go +++ b/server/internal/database/database.go @@ -1,9 +1,9 @@ package database import ( + "github.com/DaniloMurer/triffgonix/server/internal/models" "gorm.io/driver/sqlite" "gorm.io/gorm" - "server/internal/triffgonix/models" ) var database *gorm.DB diff --git a/server/internal/triffgonix/database/database_test.go b/server/internal/database/database_test.go similarity index 91% rename from server/internal/triffgonix/database/database_test.go rename to server/internal/database/database_test.go index 05f65f3..2655a0f 100644 --- a/server/internal/triffgonix/database/database_test.go +++ b/server/internal/database/database_test.go @@ -1,8 +1,8 @@ package database import ( + "github.com/DaniloMurer/triffgonix/server/internal/models" "github.com/google/uuid" - "server/internal/triffgonix/models" "testing" "github.com/stretchr/testify/assert" diff --git a/server/internal/triffgonix/domain/data.go b/server/internal/domain/data.go similarity index 96% rename from server/internal/triffgonix/domain/data.go rename to server/internal/domain/data.go index 4270f7d..9be254d 100644 --- a/server/internal/triffgonix/domain/data.go +++ b/server/internal/domain/data.go @@ -1,6 +1,8 @@ package domain -import "server/internal/triffgonix/models" +import ( + "github.com/DaniloMurer/triffgonix/server/internal/models" +) type Player struct { Id uint `json:"id"` diff --git a/server/internal/triffgonix/models/model.go b/server/internal/models/model.go similarity index 100% rename from server/internal/triffgonix/models/model.go rename to server/internal/models/model.go