-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from devilcove/reorg
Internal dir
- Loading branch information
Showing
76 changed files
with
173 additions
and
172 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 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
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
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 |
---|---|---|
@@ -1,114 +1,7 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
|
||
"github.com/devilcove/boltdb" | ||
"github.com/nats-io/nats-server/v2/server" | ||
"github.com/nats-io/nats.go" | ||
) | ||
|
||
var ( | ||
newDevice chan string | ||
brokerfail chan int | ||
webfail chan int | ||
natServer *server.Server | ||
natsOptions *server.Options | ||
natsConn *nats.Conn | ||
eConn *nats.EncodedConn | ||
) | ||
import "github.com/devilcove/plexus/internal/server" | ||
|
||
func main() { | ||
tlsConfig, err := configureServer() | ||
if err != nil { | ||
slog.Error("unable to configure server", "error", err) | ||
os.Exit(1) | ||
} | ||
defer boltdb.Close() | ||
wg := sync.WaitGroup{} | ||
quit := make(chan os.Signal, 1) | ||
reset := make(chan os.Signal, 1) | ||
brokerfail = make(chan int, 1) | ||
webfail = make(chan int, 1) | ||
newDevice = make(chan string, 1) | ||
signal.Notify(quit, syscall.SIGTERM, os.Interrupt) | ||
signal.Notify(reset, syscall.SIGHUP) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
start(ctx, &wg, tlsConfig) | ||
for { | ||
select { | ||
case <-quit: | ||
slog.Info("Shutting down...") | ||
cancel() | ||
wg.Wait() | ||
return | ||
case <-reset: | ||
slog.Info("reset...") | ||
cancel() | ||
wg.Wait() | ||
ctx, cancel = context.WithCancel(context.Background()) | ||
start(ctx, &wg, tlsConfig) | ||
case <-brokerfail: | ||
slog.Error("error running broker .... shutting down") | ||
cancel() | ||
wg.Wait() | ||
os.Exit(1) | ||
case <-webfail: | ||
slog.Error("error running web .... shutting down") | ||
cancel() | ||
wg.Wait() | ||
os.Exit(2) | ||
} | ||
} | ||
} | ||
|
||
func start(ctx context.Context, wg *sync.WaitGroup, tls *tls.Config) { | ||
wg.Add(2) | ||
go web(ctx, wg, tls) | ||
go broker(ctx, wg, tls) | ||
} | ||
|
||
func web(ctx context.Context, wg *sync.WaitGroup, tls *tls.Config) { | ||
defer wg.Done() | ||
slog.Info("Starting web server...") | ||
router := setupRouter() | ||
server := http.Server{ | ||
Addr: ":" + config.Port, | ||
Handler: router, | ||
} | ||
if config.Secure { | ||
if tls == nil { | ||
slog.Error("secure set but tls nil") | ||
webfail <- 1 | ||
} | ||
server.TLSConfig = tls | ||
server.Addr = ":443" | ||
go func() { | ||
if err := server.ListenAndServeTLS("", ""); err != nil && err != http.ErrServerClosed { | ||
slog.Error("https server", "error", err) | ||
webfail <- 1 | ||
} | ||
}() | ||
} else { | ||
go func() { | ||
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
slog.Error("http server", "error", err) | ||
webfail <- 1 | ||
} | ||
}() | ||
} | ||
slog.Info("web server started") | ||
<-ctx.Done() | ||
slog.Info("shutting down web server") | ||
if err := server.Shutdown(ctx); err != nil { | ||
slog.Error("http server shutdown", "error", err.Error()) | ||
} | ||
slog.Info("http server shutdown") | ||
server.Run() | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"context" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"crypto/tls" | ||
|
2 changes: 1 addition & 1 deletion
2
app/plexus-server/config_test.go → internal/server/config_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"testing" | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"encoding/base64" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
app/plexus-server/nathandlers.go → internal/server/nathandlers.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"errors" | ||
|
2 changes: 1 addition & 1 deletion
2
app/plexus-server/nathandlers_test.go → internal/server/nathandlers_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"net" | ||
|
2 changes: 1 addition & 1 deletion
2
app/plexus-server/network_test.go → internal/server/network_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"bytes" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"log/slog" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"bytes" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"errors" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"crypto/rand" | ||
|
2 changes: 1 addition & 1 deletion
2
app/plexus-server/router_test.go → internal/server/router_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package server | ||
|
||
import ( | ||
"io" | ||
|
Oops, something went wrong.