Skip to content

Commit

Permalink
Update for a server setup to happen before initial server or sender runs
Browse files Browse the repository at this point in the history
  • Loading branch information
jomann09 committed Feb 12, 2024
1 parent a81098f commit 3ca628d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,29 @@ type serverError struct {

var endpoints = make(map[string]Endpoint)

func Run(restart chan struct{}) {

// Get details for server
hostname, _ := os.Hostname()
host := config.Settings.GetServerHost()
config.Log.Infof("Starting server: %s (%s)", hostname, host)
func Setup() {
config.LogDebug("Setting up endpoints")
setupEndpoints()

// Check if we are using adhoc certs, if we are, generate them
if config.Settings.TLS.Cert == "adhoc" && config.Settings.TLS.Key == "adhoc" {
config.Settings.TLS.Cert = config.GetConfigFilePath("rcagent.pem")
config.Settings.TLS.Key = config.GetConfigFilePath("rcagent.key")
if !config.FileExists(config.Settings.TLS.Cert) {
config.LogDebug("Setting up certificates")
err := GenerateCert(config.Settings.TLS.Cert, config.Settings.TLS.Key)
if err != nil {
config.Log.Error(err)
}
}
}
}

setupEndpoints()
func Run(restart chan struct{}) {

// Get details for server
hostname, _ := os.Hostname()
host := config.Settings.GetServerHost()

// Add handlers and run server with config
mux := http.NewServeMux()
Expand All @@ -60,6 +63,7 @@ func Run(restart chan struct{}) {
Handler: mux,
}

config.Log.Infof("Starting server: %s (%s)", hostname, host)
go serve(srv, mux)

quit := make(chan os.Signal, 1)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (p *program) run() error {
go manager.Register()

// Set up server configuration and run
server.Setup()
c := make(chan struct{})
go runServer(c)

Expand Down

0 comments on commit 3ca628d

Please sign in to comment.