From 162e72da9222edf20a174a64bcadc0186e585cac Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Wed, 23 Nov 2022 07:41:27 +0700 Subject: [PATCH] fix: reconnect with basic auth fix: remove unused code --- src/cmd/root.go | 9 +++++---- src/config/settings.go | 1 - src/internal/rest/helpers/common.go | 9 ++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cmd/root.go b/src/cmd/root.go index 01d0412..200e378 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -73,18 +73,19 @@ func runRest(_ *cobra.Command, _ []string) { })) if config.AppBasicAuthCredential != "" { + account := make(map[string]string, 0) multipleBA := strings.Split(config.AppBasicAuthCredential, ",") for _, basicAuth := range multipleBA { ba := strings.Split(basicAuth, ":") if len(ba) != 2 { log.Fatalln("Basic auth is not valid, please this following format :") } - config.AppBasicAuthAccount[ba[0]] = ba[1] + account[ba[0]] = ba[1] } - if config.AppBasicAuthAccount != nil { + if account != nil { app.Use(basicauth.New(basicauth.Config{ - Users: config.AppBasicAuthAccount, + Users: account, })) } } @@ -116,7 +117,7 @@ func runRest(_ *cobra.Command, _ []string) { go websocket.RunHub() // Set auto reconnect to whatsapp server after booting - go helpers.SetAutoConnectAfterBooting() + go helpers.SetAutoConnectAfterBooting(appService) if err = app.Listen(":" + config.AppPort); err != nil { log.Fatalln("Failed to start: ", err.Error()) } diff --git a/src/config/settings.go b/src/config/settings.go index 130b37f..71d55a0 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -12,7 +12,6 @@ var ( AppOs = fmt.Sprintf("AldinoKemal") AppPlatform = waProto.DeviceProps_PlatformType(1) AppBasicAuthCredential string - AppBasicAuthAccount = make(map[string]string, 0) PathQrCode = "statics/qrcode" PathSendItems = "statics/senditems" diff --git a/src/internal/rest/helpers/common.go b/src/internal/rest/helpers/common.go index 6de6285..a0686bd 100644 --- a/src/internal/rest/helpers/common.go +++ b/src/internal/rest/helpers/common.go @@ -1,13 +1,12 @@ package helpers import ( - "fmt" - "github.com/aldinokemal/go-whatsapp-web-multidevice/config" - "net/http" + "context" + domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app" "time" ) -func SetAutoConnectAfterBooting() { +func SetAutoConnectAfterBooting(service domainApp.IAppService) { time.Sleep(2 * time.Second) - _, _ = http.Get(fmt.Sprintf("http://localhost:%s/app/reconnect", config.AppPort)) + _ = service.Reconnect(context.Background()) }