github.com/decred/dcrlnd@v0.7.6/lnrpc/wtclientrpc/driver.go (about) 1 package wtclientrpc 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/decred/dcrlnd/lnrpc" 8 ) 9 10 // createNewSubServer is a helper method that will create the new sub server 11 // given the main config dispatcher method. If we're unable to find the config 12 // that is meant for us in the config dispatcher, then we'll exit with an 13 // error. 14 func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) ( 15 *WatchtowerClient, lnrpc.MacaroonPerms, error) { 16 17 // We'll attempt to look up the config that we expect, according to our 18 // subServerName name. If we can't find this, then we'll exit with an 19 // error, as we're unable to properly initialize ourselves without this 20 // config. 21 subServerConf, ok := configRegistry.FetchConfig(subServerName) 22 if !ok { 23 return nil, nil, fmt.Errorf("unable to find config for "+ 24 "subserver type %s", subServerName) 25 } 26 27 // Now that we've found an object mapping to our service name, we'll 28 // ensure that it's the type we need. 29 config, ok := subServerConf.(*Config) 30 if !ok { 31 return nil, nil, fmt.Errorf("wrong type of config for "+ 32 "subserver %s, expected %T got %T", subServerName, 33 &Config{}, subServerConf) 34 } 35 36 // Before we try to make the new service instance, we'll perform 37 // some sanity checks on the arguments to ensure that they're useable. 38 switch { 39 case config.Resolver == nil: 40 return nil, nil, errors.New("a lncfg.TCPResolver is required") 41 } 42 43 return New(config) 44 } 45 46 func init() { 47 subServer := &lnrpc.SubServerDriver{ 48 SubServerName: subServerName, 49 NewGrpcHandler: func() lnrpc.GrpcHandler { 50 return &ServerShell{} 51 }, 52 } 53 54 // If the build tag is active, then we'll register ourselves as a 55 // sub-RPC server within the global lnrpc package namespace. 56 if err := lnrpc.RegisterSubServer(subServer); err != nil { 57 panic(fmt.Sprintf("failed to register sub server driver "+ 58 "'%s': %v", subServerName, err)) 59 } 60 }