Skip to content

Commit

Permalink
Merge pull request #25 from devilcove/reorg
Browse files Browse the repository at this point in the history
Internal dir
  • Loading branch information
mattkasun authored Apr 17, 2024
2 parents 0616a0a + 7161d86 commit 42bf522
Show file tree
Hide file tree
Showing 76 changed files with 173 additions and 172 deletions.
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/loglevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"runtime/debug"

"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd
import (
"fmt"

"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/kr/pretty"
"github.com/spf13/cobra"
"github.com/vishvananda/netlink"
Expand Down
2 changes: 1 addition & 1 deletion app/plexus-agent/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"

"github.com/devilcove/plexus"
"github.com/devilcove/plexus/agent"
"github.com/devilcove/plexus/internal/agent"
"github.com/spf13/cobra"
)

Expand Down
111 changes: 2 additions & 109 deletions app/plexus-server/main.go
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()
}
34 changes: 0 additions & 34 deletions app/plexus-server/server.go

This file was deleted.

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.
2 changes: 1 addition & 1 deletion app/plexus-server/broker.go → internal/server/broker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion app/plexus-server/config.go → internal/server/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"crypto/tls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"testing"
Expand Down
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
2 changes: 1 addition & 1 deletion app/plexus-server/keys.go → internal/server/keys.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"encoding/base64"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"net"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion app/plexus-server/page.go → internal/server/page.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"log/slog"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion app/plexus-server/peers.go → internal/server/peers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion app/plexus-server/router.go → internal/server/router.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"crypto/rand"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package server

import (
"io"
Expand Down
Loading

0 comments on commit 42bf522

Please sign in to comment.