From 2fa939604953b21bb82e1d10343f30a8054700a4 Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Thu, 5 Jan 2023 06:31:53 +0300 Subject: [PATCH] separate to different packages --- distribution/distribution.go | 6 ++++- distribution/domainModels.go | 11 -------- distribution/domainUtils.go | 13 --------- distribution/sessionTypes.go | 27 ------------------- models/domain/domainModels.go | 16 +++++++++++ {distribution => models/games}/fakeGames.go | 2 +- {distribution => models/games}/gameTypes.go | 8 ++++-- models/sessions/fakeSessions.go | 16 +++++++++++ utils/domain/domainUtils.go | 19 +++++++++++++ {distribution => utils/game}/gameUtils.go | 14 +++++----- {jsonUtils => utils/json}/jsonUtils.go | 0 .../session}/sessionUtils.go | 25 +++++++++-------- {updateUtils => utils/update}/updateTypes.go | 0 13 files changed, 85 insertions(+), 72 deletions(-) delete mode 100644 distribution/domainModels.go delete mode 100644 distribution/domainUtils.go delete mode 100644 distribution/sessionTypes.go create mode 100644 models/domain/domainModels.go rename {distribution => models/games}/fakeGames.go (96%) rename {distribution => models/games}/gameTypes.go (86%) create mode 100644 models/sessions/fakeSessions.go create mode 100644 utils/domain/domainUtils.go rename {distribution => utils/game}/gameUtils.go (55%) rename {jsonUtils => utils/json}/jsonUtils.go (100%) rename {distribution => utils/session}/sessionUtils.go (57%) rename {updateUtils => utils/update}/updateTypes.go (100%) diff --git a/distribution/distribution.go b/distribution/distribution.go index 6c33460..50cd771 100644 --- a/distribution/distribution.go +++ b/distribution/distribution.go @@ -1,5 +1,9 @@ package distribution +import ( + domainModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/domain" +) + type Distributiuon struct { - Domains []Domain + Domains []domainModels.Domain } diff --git a/distribution/domainModels.go b/distribution/domainModels.go deleted file mode 100644 index c2d01f5..0000000 --- a/distribution/domainModels.go +++ /dev/null @@ -1,11 +0,0 @@ -package distribution - -type Domain struct { - DiscordGroupID string - Games Games - Sessions Sessions -} - -type Domains struct { - Domains []Domain -} diff --git a/distribution/domainUtils.go b/distribution/domainUtils.go deleted file mode 100644 index 6bf7b8a..0000000 --- a/distribution/domainUtils.go +++ /dev/null @@ -1,13 +0,0 @@ -package distribution - -var fakeDomains = Domains{ //TODO: Move to back - Domains: []Domain{defaultDomain}, -} - -var defaultDomain = Domain{ - DiscordGroupID: "0", - Games: Games{ - SteamGames: SteamFakeGamesList, - }, - Sessions: FakeSessions, -} diff --git a/distribution/sessionTypes.go b/distribution/sessionTypes.go deleted file mode 100644 index 6d9ff63..0000000 --- a/distribution/sessionTypes.go +++ /dev/null @@ -1,27 +0,0 @@ -package distribution - -import ( - "time" -) - -type Session struct { - SessionId string - GameId string - Assets GameInterfaceAssets - Expires time.Time - Arguments []Argument -} - -type Sessions struct { - Sessions []Session -} - -type JSSessionInterface struct { - GameID string `json:"gameId"` - SessionId string `json:"sessionId"` - Expires time.Time `json:"expires"` - Title string `json:"title"` - Icon string `json:"icon"` - Description string `json:"description"` - Backgrounds []string `json:"backgrounds"` -} diff --git a/models/domain/domainModels.go b/models/domain/domainModels.go new file mode 100644 index 0000000..8e3f098 --- /dev/null +++ b/models/domain/domainModels.go @@ -0,0 +1,16 @@ +package distributionModels + +import ( + gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games" + sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions" +) + +type Domain struct { + DiscordGroupID string + Games gamesModels.Games + Sessions sessionsModels.Sessions +} + +type Domains struct { + Domains []Domain +} diff --git a/distribution/fakeGames.go b/models/games/fakeGames.go similarity index 96% rename from distribution/fakeGames.go rename to models/games/fakeGames.go index 86873f4..4925aa2 100644 --- a/distribution/fakeGames.go +++ b/models/games/fakeGames.go @@ -1,4 +1,4 @@ -package distribution +package gamesModels var garrysmodGame = SteamGame{ //TODO: Move to front GameId: "garrysmod", diff --git a/distribution/gameTypes.go b/models/games/gameTypes.go similarity index 86% rename from distribution/gameTypes.go rename to models/games/gameTypes.go index 2ac346c..a88a947 100644 --- a/distribution/gameTypes.go +++ b/models/games/gameTypes.go @@ -1,7 +1,7 @@ -package distribution +package gamesModels type SteamGame struct { - GameId string + GameId string //TODO: To UUID SteamId string Args []Argument OptionalArgs []Argument @@ -9,6 +9,10 @@ type SteamGame struct { Platforms map[string]bool } +type LocalGame struct { + GameId string +} + type GameInterfaceAssets struct { Title string Icon string diff --git a/models/sessions/fakeSessions.go b/models/sessions/fakeSessions.go new file mode 100644 index 0000000..c3dc501 --- /dev/null +++ b/models/sessions/fakeSessions.go @@ -0,0 +1,16 @@ +package sessionsModels + +import ( + "time" + + gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games" +) + +var fakeSession1 = Session{ + SessionId: "FakeSession1", + GameId: "fakegameid1", + Assets: gamesModels.GameInterfaceAssets{}, + Expires: time.Time{}, + Arguments: []gamesModels.Argument{}, +} +var FakeSessions = []Session{fakeSession1} diff --git a/utils/domain/domainUtils.go b/utils/domain/domainUtils.go new file mode 100644 index 0000000..0a76bc2 --- /dev/null +++ b/utils/domain/domainUtils.go @@ -0,0 +1,19 @@ +package domainUtils + +import ( + domainModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/domain" + gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games" + // sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions" +) + +var fakeDomains = domainModels.Domains{ //TODO: Move to back + Domains: []domainModels.Domain{defaultDomain}, +} + +var defaultDomain = domainModels.Domain{ + DiscordGroupID: "0", + Games: gamesModels.Games{ + SteamGames: gamesModels.SteamFakeGamesList, + }, + // Sessions: sessionsModels.FakeSessions, +} diff --git a/distribution/gameUtils.go b/utils/game/gameUtils.go similarity index 55% rename from distribution/gameUtils.go rename to utils/game/gameUtils.go index 15aad2c..1d7e73c 100644 --- a/distribution/gameUtils.go +++ b/utils/game/gameUtils.go @@ -1,12 +1,14 @@ -package distribution +package gameUtils -func FindGameByID(id string, list Games) SteamGame { +import gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games" + +func FindGameByID(id string, list gamesModels.Games) gamesModels.SteamGame { for _, game := range list.SteamGames { if game.GameId == id { return game } } - var temp SteamGame = SteamGame{} + var temp gamesModels.SteamGame = gamesModels.SteamGame{} return temp } @@ -20,8 +22,8 @@ func FindGameByID(id string, list Games) SteamGame { // return game // } -func GetJSGameInterface(game SteamGame) JSGameInterface { - newInterface := JSGameInterface{ +func GetJSGameInterface(game gamesModels.SteamGame) gamesModels.JSGameInterface { + newInterface := gamesModels.JSGameInterface{ GameID: game.GameId, Title: game.Assets.Title, Icon: game.Assets.Icon, @@ -30,6 +32,6 @@ func GetJSGameInterface(game SteamGame) JSGameInterface { return newInterface } -func ArgToStr(a Argument) string { +func ArgToStr(a gamesModels.Argument) string { return a.Body + " " + a.Value } diff --git a/jsonUtils/jsonUtils.go b/utils/json/jsonUtils.go similarity index 100% rename from jsonUtils/jsonUtils.go rename to utils/json/jsonUtils.go diff --git a/distribution/sessionUtils.go b/utils/session/sessionUtils.go similarity index 57% rename from distribution/sessionUtils.go rename to utils/session/sessionUtils.go index 63cccbb..45d0c58 100644 --- a/distribution/sessionUtils.go +++ b/utils/session/sessionUtils.go @@ -1,33 +1,36 @@ -package distribution +package sessionUtils import ( "encoding/json" "time" + + gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games" + sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions" ) -func ConvertServerSessionsToJSON(s Session) []byte { +func ConvertServerSessionsToJSON(s sessionsModels.Session) []byte { s_json, err := json.Marshal(s) _ = err //TODO: Check Errors return s_json } -func FindSessionByID(sessionId string, sessions []Session) Session { +func FindSessionByID(sessionId string, sessions []sessionsModels.Session) sessionsModels.Session { for _, session := range sessions { if session.SessionId == sessionId { return session } } - return Session{ //TODO: Return Errors + return sessionsModels.Session{ //TODO: Return Errors SessionId: sessionId, GameId: "", - Assets: GameInterfaceAssets{}, + Assets: gamesModels.GameInterfaceAssets{}, Expires: time.Time{}, - Arguments: []Argument{}, + Arguments: []gamesModels.Argument{}, } } -func GetJSSessionInterface(s Session) JSSessionInterface { - newInterface := JSSessionInterface{ //TODO: If session icon empty - use game icon +func GetJSSessionInterface(s sessionsModels.Session) sessionsModels.JSSessionInterface { + newInterface := sessionsModels.JSSessionInterface{ //TODO: If session icon empty - use game icon GameID: s.GameId, SessionId: s.SessionId, Expires: time.Time{}, @@ -39,8 +42,8 @@ func GetJSSessionInterface(s Session) JSSessionInterface { return newInterface } -var FakeSessions = Sessions{ //TODO: Move to front - Sessions: []Session{ +var FakeSessions = sessionsModels.Sessions{ //TODO: Move to front + Sessions: []sessionsModels.Session{ { GameId: "garrysmod", SessionId: "gmod-test", @@ -49,7 +52,7 @@ var FakeSessions = Sessions{ //TODO: Move to front // Status: "Super fake session", // Version: "", Expires: time.Time{}, - Arguments: []Argument{ + Arguments: []gamesModels.Argument{ { Body: "+connect", Value: "127.0.0.1:27015", diff --git a/updateUtils/updateTypes.go b/utils/update/updateTypes.go similarity index 100% rename from updateUtils/updateTypes.go rename to utils/update/updateTypes.go