sharedutils/utils/session/sessionUtils.go

44 lines
1.2 KiB
Go
Raw Normal View History

2023-01-05 03:31:53 +00:00
package sessionUtils
2022-11-11 12:15:36 +00:00
import (
"encoding/json"
"time"
2023-01-05 03:31:53 +00:00
gamesModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/games"
sessionsModels "git.gregbrzezinski.com/Skirda/skirdagoutils/models/sessions"
2022-11-11 12:15:36 +00:00
)
2023-01-05 03:31:53 +00:00
func ConvertServerSessionsToJSON(s sessionsModels.Session) []byte {
2022-11-11 12:15:36 +00:00
s_json, err := json.Marshal(s)
_ = err //TODO: Check Errors
return s_json
}
2023-01-05 03:31:53 +00:00
func FindSessionByID(sessionId string, sessions []sessionsModels.Session) sessionsModels.Session {
2022-11-11 12:30:08 +00:00
for _, session := range sessions {
if session.SessionId == sessionId {
return session
}
}
2023-01-05 03:31:53 +00:00
return sessionsModels.Session{ //TODO: Return Errors
2022-11-11 12:30:08 +00:00
SessionId: sessionId,
GameId: "",
2023-01-05 03:31:53 +00:00
Assets: gamesModels.GameInterfaceAssets{},
2022-11-11 12:30:08 +00:00
Expires: time.Time{},
2023-01-05 03:31:53 +00:00
Arguments: []gamesModels.Argument{},
2022-11-11 12:30:08 +00:00
}
}
2023-01-05 03:31:53 +00:00
func GetJSSessionInterface(s sessionsModels.Session) sessionsModels.JSSessionInterface {
newInterface := sessionsModels.JSSessionInterface{ //TODO: If session icon empty - use game icon
2022-11-11 23:56:43 +00:00
GameID: s.GameId,
SessionId: s.SessionId,
Expires: time.Time{},
Title: s.Assets.Title,
Icon: s.Assets.Icon,
Description: s.Assets.Description,
Backgrounds: []string{}, //TODO: Complete
}
return newInterface
}