diff --git a/examples/go_service/main.go b/examples/go_service/main.go index 30178c034..2f8efbfb9 100644 --- a/examples/go_service/main.go +++ b/examples/go_service/main.go @@ -5,8 +5,12 @@ import ( "fmt" "log" "net" + "os" + "github.com/sirupsen/logrus" + "github.com/slackhq/nebula" "github.com/slackhq/nebula/config" + "github.com/slackhq/nebula/overlay" "github.com/slackhq/nebula/service" ) @@ -59,7 +63,16 @@ pki: if err := cfg.LoadString(configStr); err != nil { return err } - svc, err := service.New(&cfg) + + logger := logrus.New() + logger.Out = os.Stdout + + ctrl, err := nebula.Main(&cfg, false, "custom-app", logger, overlay.NewUserDeviceFromConfig) + if err != nil { + return err + } + + svc, err := service.New(ctrl) if err != nil { return err } diff --git a/service/service.go b/service/service.go index 4ddd30182..ff16400ea 100644 --- a/service/service.go +++ b/service/service.go @@ -9,13 +9,10 @@ import ( "math" "net" "net/netip" - "os" "strings" "sync" - "github.com/sirupsen/logrus" "github.com/slackhq/nebula" - "github.com/slackhq/nebula/config" "github.com/slackhq/nebula/overlay" "golang.org/x/sync/errgroup" "gvisor.dev/gvisor/pkg/buffer" @@ -46,14 +43,7 @@ type Service struct { } } -func New(config *config.C) (*Service, error) { - logger := logrus.New() - logger.Out = os.Stdout - - control, err := nebula.Main(config, false, "custom-app", logger, overlay.NewUserDeviceFromConfig) - if err != nil { - return nil, err - } +func New(control *nebula.Control) (*Service, error) { control.Start() ctx := control.Context() diff --git a/service/service_test.go b/service/service_test.go index 31762090d..eb654c4d2 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -5,13 +5,17 @@ import ( "context" "errors" "net/netip" + "os" "testing" "time" "dario.cat/mergo" + "github.com/sirupsen/logrus" + "github.com/slackhq/nebula" "github.com/slackhq/nebula/cert" "github.com/slackhq/nebula/config" "github.com/slackhq/nebula/e2e" + "github.com/slackhq/nebula/overlay" "golang.org/x/sync/errgroup" "gopkg.in/yaml.v2" ) @@ -71,7 +75,15 @@ func newSimpleService(caCrt *cert.NebulaCertificate, caKey []byte, name string, panic(err) } - s, err := New(&c) + logger := logrus.New() + logger.Out = os.Stdout + + control, err := nebula.Main(&c, false, "custom-app", logger, overlay.NewUserDeviceFromConfig) + if err != nil { + panic(err) + } + + s, err := New(control) if err != nil { panic(err) }