serverless arch

This commit is contained in:
2025-05-11 02:32:33 +02:00
parent 15b1efcc48
commit 30c71cb449
8 changed files with 291 additions and 27 deletions

View File

@@ -70,6 +70,33 @@ func All() ([]Remote, error) {
return remotes, nil
}
func One(gameID string) (Remote, error) {
content, err := os.ReadFile(filepath.Join(datastorepath, gameID, "remote.json"))
if err != nil {
return Remote{}, err
}
var r Remote
err = json.Unmarshal(content, &r)
if err != nil {
return Remote{}, fmt.Errorf("corrupted datastore: failed to parse %s/remote.json: %w", gameID, err)
}
content, err = os.ReadFile(filepath.Join(datastorepath, gameID, "metadata.json"))
if err != nil {
return Remote{}, fmt.Errorf("corrupted datastore: failed to read %s/metadata.json: %w", gameID, err)
}
var m game.Metadata
err = json.Unmarshal(content, &m)
if err != nil {
return Remote{}, fmt.Errorf("corrupted datastore: failed to parse %s/metadata.json: %w", gameID, err)
}
r.GameID = m.ID
return r, nil
}
func Set(gameID, url string) error {
r := Remote{
URL: url,