Skip to content

Commit

Permalink
Update README, added example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
arslanbekov committed Jan 11, 2024
1 parent 3555e1a commit e7c0231
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
# CloudConnexa Go Client

This Go library enables access to the CloudConnexa API, as detailed in the [CloudConnexa API Documentation](https://openvpn.net/cloud-docs/developer/cloudconnexa-api.html).

## Installation Instructions

To install the cloudconnexa-go-client, ensure you are using a modern Go release that supports module mode. With Go set up, execute the following command:

```sh
go get github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa
```

## How to Use

In your Go project, you can use the library by importing it as follows:

```go
import "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
```
```

Instantiate a new CloudConnexa client. Subsequently, utilize the diverse services provided by the client to interact with distinct segments of the CloudConnexa API. For instance:

```go
client := cloudconnexa.NewClient("api_url", "client_id", "client_secret")

// List connectors
connectors, _, err := client.Connectors.List(ctx, nil)
```

## Authentication

For auth need to pass three parameters:
1. client_id
2. client_secret
3. api_url (example: `https://myorg.api.openvpn.com`)

```go
package main

import (
"fmt"
"log"

"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
)

func main() {
client, err := cloudconnexa.NewClient("api_url", "client_id", "client_secret")
if err != nil {
log.Fatalf("error creating client: %v", err)
}

networkId := "your_network_id"
routes, err := client.Routes.List(networkId)
if err != nil {
log.Fatalf("error getting routes: %v", err)
}

fmt.Println("Received routes:", routes)
}
```
8 changes: 4 additions & 4 deletions cloudconnexa/connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *ConnectorsService) GetByPage(page int, pageSize int) (ConnectorPageResp
return response, nil
}

func (c *ConnectorsService) GetAll() ([]Connector, error) {
func (c *ConnectorsService) List() ([]Connector, error) {
var allConnectors []Connector
page := 1
pageSize := 10
Expand All @@ -75,7 +75,7 @@ func (c *ConnectorsService) GetAll() ([]Connector, error) {
}

func (c *ConnectorsService) GetByName(name string) (*Connector, error) {
connectors, err := c.GetAll()
connectors, err := c.List()
if err != nil {
return nil, err
}
Expand All @@ -89,7 +89,7 @@ func (c *ConnectorsService) GetByName(name string) (*Connector, error) {
}

func (c *ConnectorsService) GetByID(connectorID string) (*Connector, error) {
connectors, err := c.GetAll()
connectors, err := c.List()
if err != nil {
return nil, err
}
Expand All @@ -103,7 +103,7 @@ func (c *ConnectorsService) GetByID(connectorID string) (*Connector, error) {
}

func (c *ConnectorsService) GetByNetworkID(networkId string) ([]Connector, error) {
connectors, err := c.GetAll()
connectors, err := c.List()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e7c0231

Please sign in to comment.