mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
add -apply flag, add webserver
This commit is contained in:
parent
cb5554dcfe
commit
0232a5c4f4
3 changed files with 93 additions and 10 deletions
32
pkg/server/server.go
Normal file
32
pkg/server/server.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
|
||||
"nfsense.net/nfsense/pkg/definitions"
|
||||
)
|
||||
|
||||
var server http.Server
|
||||
|
||||
func StartWebserver(conf *definitions.Config) {
|
||||
server.Addr = ":8080"
|
||||
go func() {
|
||||
if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
|
||||
slog.Error("Webserver error", err)
|
||||
}
|
||||
slog.Info("Webserver Stopped")
|
||||
}()
|
||||
}
|
||||
|
||||
func ShutdownWebserver(ctx context.Context) error {
|
||||
err := server.Shutdown(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Shutting down: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue