-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split http and wails into two entrypoints
- Loading branch information
Showing
10 changed files
with
128 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//go:build !wails || http | ||
// +build !wails http | ||
|
||
// (http tag above is simply to fix go language server issue and is not needed to build the app) | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"sync" | ||
"time" | ||
|
||
echologrus "github.com/davrux/echo-logrus/v4" | ||
"github.com/labstack/echo/v4" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// ignore this warning: we use build tags | ||
// this function will only be executed if no wails tag is set | ||
func main() { | ||
log.Info("NWC Starting in HTTP mode") | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
|
||
svc := CreateService(&wg) | ||
|
||
if svc.cfg.CookieSecret == "" { | ||
svc.Logger.Fatalf("required key COOKIE_SECRET missing value") | ||
} | ||
|
||
echologrus.Logger = svc.Logger | ||
e := echo.New() | ||
|
||
// Alby backend only supported in HTTP app type | ||
if svc.cfg.LNBackendType == AlbyBackendType { | ||
oauthService, err := NewAlbyOauthService(svc, e) | ||
if err != nil { | ||
svc.Logger.Fatal(err) | ||
} | ||
svc.lnClient = oauthService | ||
} else { | ||
err := svc.launchLNBackend() | ||
if err != nil { | ||
// LN backend not needed immediately, just log errors | ||
svc.Logger.Warnf("Failed to launch LN backend: %v", err) | ||
} | ||
} | ||
|
||
//register shared routes | ||
svc.RegisterSharedRoutes(e) | ||
//start Echo server | ||
go func() { | ||
if err := e.Start(fmt.Sprintf(":%v", svc.cfg.Port)); err != nil && err != http.ErrServerClosed { | ||
e.Logger.Fatal("shutting down the server") | ||
} | ||
//handle graceful shutdown | ||
<-svc.ctx.Done() | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
e.Shutdown(ctx) | ||
svc.Logger.Info("Echo server exited") | ||
wg.Done() | ||
}() | ||
|
||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build wails | ||
// +build wails | ||
|
||
package main | ||
|
||
import ( | ||
"sync" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// ignore this warning: we use build tags | ||
// this function will only be executed if the wails tag is set | ||
func main() { | ||
log.Info("NWC Starting in WAILS mode") | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
|
||
svc := CreateService(&wg) | ||
|
||
go func() { | ||
app := NewApp(svc) | ||
LaunchWailsApp(app) | ||
wg.Done() | ||
svc.Logger.Info("Wails app exited") | ||
}() | ||
|
||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters