frends-sdk-go
Frends SDK for Go. For those who have used the MSGraph SDK for Go, this should look very familiar.
Regenerate client
To regenerate the client, you need to install Kiota. You can find the installation instructions here.
Download the swagger API specification from your frends instance at https://[instance].frendsapp.com/swagger/v1.0/swagger.json
Once you have Kiota installed, you can regenerate the client by deleting the client folder and running the following command:
bash generate.sh
Usage
Basic
First, set the required environment variables. You can either set them by exporting them in your current environment/shell, or by using a .env file and a library like godotenv.
export FRENDS_BASE_URL=https://my-frends-instance.frendsapp.com/api/v1
export AZURE_TENANT_NAME=my-tenant-name
export AZURE_API_RESOURCE=api://my-api-resource-id
export AZURE_CLIENT_ID=my-client-id
export AZURE_CLIENT_SECRET=my-client-secret
Then, you can use the SDK in your Go code like this:
package main
import (
"context"
"log"
"github.com/joho/godotenv"
"github.com/kommunkod/frends-sdk-go/sdk"
)
func main() {
// Load environment variables from .env file if it exists
godotenv.Load(".env")
// Create a new Frends client using environment variables
client, err := sdk.NewFrendsClientFromEnv()
if err != nil {
log.Fatalf("Error creating Frends client: %v\n", err)
}
// Get a list of environments
resp, err := client.Environments().Get(context.Background(), nil)
if err != nil {
log.Fatalf("Error getting environments: %v\n", err)
}
for _, env := range resp.GetData() {
log.Printf("Environment: ID=%d, Name=%s\n", *env.GetId(), *env.GetDisplayName())
}
}
You can also specify the base URL and authentication parameters directly in code:
client, err := sdk.NewFrendsClient(
"https://my-frends-instance.frendsapp.com/api/v1",
"my-tenant-name",
"my-client-id",
"my-client-secret",
"api://my-api-resource-id"
)
if err != nil {
log.Fatalf("Error creating Frends client: %v\n", err)
}