github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/providers/discovery/external/options.go (about)

     1  // Copyright (c) 2021-2022, R.I. Pienaar and the Choria Project contributors
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package external
     6  
     7  import (
     8  	"time"
     9  
    10  	"github.com/choria-io/go-choria/protocol"
    11  )
    12  
    13  type dOpts struct {
    14  	filter     *protocol.Filter
    15  	collective string
    16  	timeout    time.Duration
    17  	command    string
    18  	do         map[string]string
    19  }
    20  
    21  // DiscoverOption configures the broadcast discovery method
    22  type DiscoverOption func(o *dOpts)
    23  
    24  // Filter sets the filter to use for the discovery, else a blank one is used
    25  func Filter(f *protocol.Filter) DiscoverOption {
    26  	return func(o *dOpts) {
    27  		o.filter = f
    28  	}
    29  }
    30  
    31  // Collective sets the collective to discover in, else main collective is used
    32  func Collective(c string) DiscoverOption {
    33  	return func(o *dOpts) {
    34  		o.collective = c
    35  	}
    36  }
    37  
    38  // Timeout sets the discovery timeout, else the configured default is used
    39  func Timeout(t time.Duration) DiscoverOption {
    40  	return func(o *dOpts) {
    41  		o.timeout = t
    42  	}
    43  }
    44  
    45  func Command(c string) DiscoverOption {
    46  	return func(o *dOpts) {
    47  		o.command = c
    48  	}
    49  }
    50  
    51  // DiscoveryOptions sets the key value pairs that make user supplied discovery options.
    52  //
    53  // Supported options:
    54  //
    55  //	command - The command to execute instead of configured default
    56  //
    57  // All options will be passed to the external command in the request, so other
    58  // command specific options is supported and will be ignored by this code
    59  func DiscoveryOptions(opt map[string]string) DiscoverOption {
    60  	return func(o *dOpts) {
    61  		o.do = opt
    62  	}
    63  }