add go example connect to lps

This commit is contained in:
ruben beck
2023-07-12 14:43:39 +02:00
parent 47e9c21f9a
commit 9ba9463d28
2 changed files with 34 additions and 3 deletions

View File

@@ -58,7 +58,7 @@ Based on the API key provided to the Breez SDK, a default LSP is selected for yo
```python
try:
lsp_id = self.sdk_services.lsp_id()
lsp_id = sdk_services.lsp_id()
lsp_info = sdk_services.fetch_lsp_info(lsp_id)
except Exception as error:
@@ -75,4 +75,31 @@ except Exception as error:
```
</section>
<div slot="title">Go</div>
<section>
Based on the API key provided to the Breez SDK, a default LSP is selected for your node to provide liquidity to it. To get the information about the selected LSP you can do the following:
```go
lspId, err := sdkServices.LspId()
if err != nil {
// Handle error
}
lspInfo, err := sdkServices.FetchLspInfo(*lspId)
if err != nil {
// Handle error
}
```
When you have selected an LSP you may then connect to it.
```go
err = sdkServices.ConnectLsp(*lspId)
if err != nil {
// Handle error
}
```
</custom-tabs>

View File

@@ -236,6 +236,11 @@ func (BreezListener) OnEvent(e breez_sdk.BreezEvent) {
}
// Create the default config
seed, err := breez_sdk.MnemonicToSeed("<mnemonics words>")
if err != nil {
log.Fatalf("MnemonicToSeed failed: %#v", err)
}
apiKey := "<your breez api key>"
inviteCode := "<your greenlight invite code>"
nodeConfig := breez_sdk.NodeConfigGreenlight{
@@ -255,9 +260,8 @@ if err != nil {
config.workingDir = "path to an existing directory"
sdkServices, err := breez_sdk.Connect(config, seed, BreezListener{})
if err != nil {
log.Fatalf("Connect failed: %#v", err)
log.Fatalf("Connect failed: %#v", err)
}
```
At any point we can fetch our balance from the Greenlight node: