github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/integration/testbroker/broker.go (about)

     1  // Copyright (c) 2022, R.I. Pienaar and the Choria Project contributors
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package testbroker
     6  
     7  import (
     8  	"context"
     9  	"sync"
    10  
    11  	"github.com/choria-io/go-choria/broker/network"
    12  	"github.com/choria-io/go-choria/choria"
    13  	"github.com/choria-io/go-choria/config"
    14  	"github.com/sirupsen/logrus"
    15  )
    16  
    17  func StartNetworkBrokerWithConfigFile(ctx context.Context, wg *sync.WaitGroup, file string, log *logrus.Logger) (*network.Server, error) {
    18  	cfg, err := config.NewConfig(file)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  	cfg.CustomLogger = log
    23  
    24  	fw, err := choria.NewWithConfig(cfg)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	srv, err := network.NewServer(fw, fw.BuildInfo(), fw.Configuration().LogLevel == "debug")
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	wg.Add(1)
    35  	go srv.Start(ctx, wg)
    36  
    37  	return srv, nil
    38  }