From 56b90e81ca861c4f11d874488ce51ca8a4723b2a Mon Sep 17 00:00:00 2001 From: iAmir Date: Sun, 8 Oct 2023 00:11:00 +0330 Subject: [PATCH] proper launcher api with more information --- app/transports/api/api.go | 6 ++---- app/transports/api/launcher/api.go | 31 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 app/transports/api/launcher/api.go diff --git a/app/transports/api/api.go b/app/transports/api/api.go index 997a3f921..36a729094 100644 --- a/app/transports/api/api.go +++ b/app/transports/api/api.go @@ -13,6 +13,7 @@ import ( "github.com/openmultiplayer/web/app/services/authentication" "github.com/openmultiplayer/web/app/transports/api/auth" "github.com/openmultiplayer/web/app/transports/api/docs" + "github.com/openmultiplayer/web/app/transports/api/launcher" "github.com/openmultiplayer/web/app/transports/api/legacy" "github.com/openmultiplayer/web/app/transports/api/metrics" "github.com/openmultiplayer/web/app/transports/api/pawndex" @@ -32,6 +33,7 @@ func Build() fx.Option { servers.Build(), users.Build(), pawndex.Build(), + launcher.Build(), // Starts the HTTP server in a goroutine and fatals if it errors. fx.Invoke(func(l *zap.Logger, server *http.Server) { @@ -72,10 +74,6 @@ func Build() fx.Option { web.Write(w, map[string]string{"version": version.Version}) //nolint:errcheck }) - router.Get("/launcher", func(w http.ResponseWriter, r *http.Request) { - web.Write(w, map[string]string{"version": cfg.LauncherVersion, "download": "https://github.com/openmultiplayer/launcher/releases"}) //nolint:errcheck - }) - router.HandleFunc( "/{rest:[a-zA-Z0-9=\\-\\/]+}", func(w http.ResponseWriter, r *http.Request) { diff --git a/app/transports/api/launcher/api.go b/app/transports/api/launcher/api.go new file mode 100644 index 000000000..9a337ebc9 --- /dev/null +++ b/app/transports/api/launcher/api.go @@ -0,0 +1,31 @@ +package launcher + +import ( + "net/http" + + "github.com/go-chi/chi" + "github.com/openmultiplayer/web/internal/config" + "github.com/openmultiplayer/web/internal/web" + "go.uber.org/fx" +) + +func Build() fx.Option { + return fx.Options( + fx.Invoke(func( + r chi.Router, + cfg config.Config, + ) { + + launcherInfo := map[string]string{ + "version": cfg.LauncherVersion, + "download": "https://github.com/openmultiplayer/launcher/releases", + "changelog": `|- Build 1 - 2023/10/08 +Release beta version`, + } + + r.Get("/launcher", func(w http.ResponseWriter, r *http.Request) { + web.Write(w, launcherInfo) //nolint:errcheck + }) + }), + ) +}