client io architecture

This commit is contained in:
Ilia Denisov
2026-03-12 18:45:46 +02:00
committed by GitHub
parent 2dafa69b93
commit 079b9facb0
36 changed files with 1810 additions and 460 deletions
+35
View File
@@ -0,0 +1,35 @@
package connector
import (
model "galaxy/model/client"
"galaxy/model/report"
)
// Connector is a main interface to provide connectivity with app's server.
type Connector interface {
UIConnector
// CheckConnection is called asynchronously every 5 seconds and tests is connection available with a specific backend server endpoint.
// There is guaranteed backoff 5s -> 15s -> 30s -> 60s when no connection is available.
CheckConnection() bool
// CheckVersion is called asynchronously every 30 minutes and receives from backend server information about currently available app versions.
CheckVersion() ([]VersionInfo, error)
// DownloadVersion asynchronously retrieves from a specific string URL a binary artifact from backend server.
DownloadVersion(string) ([]byte, error)
}
// UIConnector contains only funcs are needed for the client app to be functional.
type UIConnector interface {
// FetchReport asynchronously requests from backend server a [report.Report] for a given [model.GameID] and turn number.
// Passed callback func will will accept non-nil error in case of I/O or decoding errors occuried,
// otherwise callback func accepts loaded [report.Report].
FetchReport(model.GameID, uint, func(report.Report, error))
}
type VersionInfo struct {
OS string `json:"os"` // Operating System name (unix, darwin, windows, etc.)
Version string `json:"version"` // Semver format: X.Y.Z
URL string `json:"url"` // URL for download artifacto for this version
}
+3
View File
@@ -0,0 +1,3 @@
module galaxy/connector
go 1.26.0
+24
View File
@@ -0,0 +1,24 @@
// Package implements "galaxy/connector.Connector" interface with HTTP REST API protocol
package http
import (
"context"
"net/url"
)
type httpConnector struct {
ctx context.Context
backendURL *url.URL // HTTP REST API Server URL
}
func NewHttpConnector(ctx context.Context, backendURL string) (*httpConnector, error) {
u, err := url.Parse(backendURL)
if err != nil {
return nil, err
}
h := &httpConnector{
ctx: ctx,
backendURL: u,
}
return h, nil
}