@@ -13,11 +13,48 @@ import (
1313 macaroon "gopkg.in/macaroon.v2"
1414)
1515
16+ // BasicClientOption is a functional option argument that allows adding arbitrary
17+ // lnd basic client configuration overrides, without forcing existing users of
18+ // NewBasicClient to update their invocation. These are always processed in
19+ // order, with later options overriding earlier ones.
20+ type BasicClientOption func (* basicClientOptions )
21+
22+ // basicClientOptions is a set of options that can configure the lnd client
23+ // returned by NewBasicClient.
24+ type basicClientOptions struct {
25+ macFilename string
26+ }
27+
28+ // defaultBasicClientOptions returns a basicClientOptions set to lnd basic client
29+ // defaults.
30+ func defaultBasicClientOptions () * basicClientOptions {
31+ return & basicClientOptions {
32+ macFilename : defaultAdminMacaroonFilename ,
33+ }
34+ }
35+
36+ // MacFilename is a basic client option that sets the name of the macaroon file
37+ // to use.
38+ func MacFilename (macFilename string ) BasicClientOption {
39+ return func (bc * basicClientOptions ) {
40+ bc .macFilename = macFilename
41+ }
42+ }
43+
44+ // applyBasicClientOptions updates a basicClientOptions set with functional
45+ // options.
46+ func (bc * basicClientOptions ) applyBasicClientOptions (options ... BasicClientOption ) {
47+ for _ , option := range options {
48+ option (bc )
49+ }
50+ }
51+
1652// NewBasicClient creates a new basic gRPC client to lnd. We call this client
17- // "basic" as it uses a global macaroon (by default the admin macaroon) for the
18- // entire connection, and falls back to expected defaults if the arguments
19- // aren't provided.
20- func NewBasicClient (lndHost , tlsPath , macDir , network string ) (lnrpc.LightningClient , error ) {
53+ // "basic" as it falls back to expected defaults if the arguments aren't
54+ // provided.
55+ func NewBasicClient (lndHost , tlsPath , macDir , network string , basicOptions ... BasicClientOption ) (
56+ lnrpc.LightningClient , error ) {
57+
2158 if tlsPath == "" {
2259 tlsPath = defaultTLSCertPath
2360 }
@@ -40,7 +77,12 @@ func NewBasicClient(lndHost, tlsPath, macDir, network string) (lnrpc.LightningCl
4077 )
4178 }
4279
43- macPath := filepath .Join (macDir , defaultAdminMacaroonFilename )
80+ // Starting with the set of default options, we'll apply any specified
81+ // functional options to the basic client.
82+ bco := defaultBasicClientOptions ()
83+ bco .applyBasicClientOptions (basicOptions ... )
84+
85+ macPath := filepath .Join (macDir , bco .macFilename )
4486
4587 // Load the specified macaroon file.
4688 macBytes , err := ioutil .ReadFile (macPath )
0 commit comments