Repository: syncthing/syncthing
File: lib/connections/service.go (Go)

Code before:
	LANAddresses []string `json:"lanAddresses"`
	WANAddresses []string `json:"wanAddresses"`
}

type ConnectionStatusEntry struct {
	When  time.Time `json:"when"`
	Error *string   `json:"error"`
}

type service struct {
	*suture.Supervisor
	connectionStatusHandler

	cfg                    config.Wrapper
	deviceAddressesChanged chan struct{}
	myID                   protocol.DeviceID
	model                  Model
	tlsCfg                 *tls.Config
	discoverer             discover.Finder
	conns                  chan internalConn
	bepProtocolName        string
	tlsDefaultCommonName   string
	limiter                *limiter
	natService             *nat.Service
	evLogger               events.Logger

	listenersMut       sync.RWMutex
	listeners          map[string]genericListener
	listenerTokens     map[string]suture.ServiceToken
	listenerSupervisor *suture.Supervisor
}

func NewService(cfg config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *tls.Config, discoverer discover.Finder, bepProtocolName string, tlsDefaultCommonName string, evLogger events.Logger) Service {
	spec := svcutil.SpecWithInfoLogger(l)
	service := &service{
		Supervisor:              suture.New("connections.Service", spec),
		connectionStatusHandler: newConnectionStatusHandler(),

		cfg:                    cfg,
		deviceAddressesChanged: make(chan struct{}),
		myID:                   myID,
		model:                  mdl,
		tlsCfg:                 tlsCfg,
		discoverer:             discoverer,
		conns:                  make(chan internalConn),
		bepProtocolName:        bepProtocolName,
		tlsDefaultCommonName:   tlsDefaultCommonName,
		limiter:                newLimiter(myID, cfg),
		natService:             nat.NewService(myID, cfg),
		evLogger:               evLogger,


Review comment (suggestion):
The order of the early variables in the struct matches those of passed in parameters, I'd put this further down (maybe after the `evLogger`) as it's an internally constructed thing.

Code after:
	LANAddresses []string `json:"lanAddresses"`
	WANAddresses []string `json:"wanAddresses"`
}

type ConnectionStatusEntry struct {
	When  time.Time `json:"when"`
	Error *string   `json:"error"`
}

type service struct {
	*suture.Supervisor
	connectionStatusHandler

	cfg                  config.Wrapper
	myID                 protocol.DeviceID
	model                Model
	tlsCfg               *tls.Config
	discoverer           discover.Finder
	conns                chan internalConn
	bepProtocolName      string
	tlsDefaultCommonName string
	limiter              *limiter
	natService           *nat.Service
	evLogger             events.Logger

	deviceAddressesChanged chan struct{}
	listenersMut           sync.RWMutex
	listeners              map[string]genericListener
	listenerTokens         map[string]suture.ServiceToken
	listenerSupervisor     *suture.Supervisor
}

func NewService(cfg config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *tls.Config, discoverer discover.Finder, bepProtocolName string, tlsDefaultCommonName string, evLogger events.Logger) Service {
	spec := svcutil.SpecWithInfoLogger(l)
	service := &service{
		Supervisor:              suture.New("connections.Service", spec),
		connectionStatusHandler: newConnectionStatusHandler(),

		cfg:                  cfg,
		myID:                 myID,
		model:                mdl,
		tlsCfg:               tlsCfg,
		discoverer:           discoverer,
		conns:                make(chan internalConn),
		bepProtocolName:      bepProtocolName,
		tlsDefaultCommonName: tlsDefaultCommonName,
		limiter:              newLimiter(myID, cfg),
		natService:           nat.NewService(myID, cfg),
		evLogger:             evLogger,

		deviceAddressesChanged: make(chan struct{}, 1),