Categorygithub.com/bleemeo/bleemeo-go
modulepackage
0.1.0
Repository: https://github.com/bleemeo/bleemeo-go.git
Documentation: pkg.go.dev

# README

Bleemeo Go Go Report Card Go Reference License

Go library for interacting with the Bleemeo API

Requirements

  • Go1.19 or later
  • An account on Bleemeo

Installation

On your existing Go project, run:

go get -u github.com/bleemeo/bleemeo-go

If you start a new project, use go mod init to bootstrap the Go project:

go mod init github.com/my-username/my-project

Then do the first command.

Documentation

The Go library documentation can be found here.

Some examples of library usage can be found in examples.

Basic usage

Listing the first 10 agents in your account:

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"net/url"

	"github.com/bleemeo/bleemeo-go"
)

func main() {
	client, err := bleemeo.NewClient(bleemeo.WithConfigurationFromEnv())
	if err != nil {
		log.Fatalln("Failed to initialize client:", err)
	}

	defer func() {
		err := client.Logout(context.Background())
		if err != nil {
			log.Fatalln("Logout:", err)
		}
	}()

	const pageSize = 10

	page, err := client.GetPage(context.Background(), bleemeo.ResourceAgent, 1, pageSize, url.Values{"active": {"true"}})
	if err != nil {
		log.Fatalln("Failed to list agents:", err)
	}

	for _, row := range page.Results {
		var agentObj struct {
			ID          string `json:"id"`
			FQDN        string `json:"fqdn"`
			DisplayName string `json:"display_name"`
		}

		err = json.Unmarshal(row, &agentObj)
		if err != nil {
			log.Fatalln("Failed to unmarshal agent:", err)
		}

		fmt.Printf("* Agent %s (fqdn = %s, id = %s)\n", agentObj.DisplayName, agentObj.FQDN, agentObj.ID)
	}
}

Save this file in list-agents.go.

If not already in an existing Go project, create the project:

go mod init github.com/my-username/my-project

Run with:

go get -u github.com/bleemeo/bleemeo-go
[email protected] BLEEMEO_PASSWORD=password go run list-agents.go

More examples can be found in examples

To run an example, from a clone of this repository run the following:

[email protected] BLEEMEO_PASSWORD=password go run ./examples/list_metrics/

Environment

At least the following options must be configured (as environment variables or with options):

  • Credentials OR initial refresh token
  • All other configuration options are optional and may be omitted

Ways to provide those options are referenced in the Configuration section.

Configuration

For environment variables to be taken into account, the option WithConfigurationFromEnv() must be provided.

PropertyOption functionEnv variable(s)Default values
CredentialsWithCredentials(username, password)BLEEMEO_USER & BLEEMEO_PASSWORDNone. This option is required (unless initial refresh token is used)
Bleemeo account headerWithBleemeoAccountHeader(accountID)BLEEMEO_ACCOUNT_IDThe first account associated with used credentials.
OAuth client ID/secretWithOAuthClient(id, secret)BLEEMEO_OAUTH_CLIENT_ID & BLEEMEO_OAUTH_CLIENT_SECRETThe default SDK OAuth client ID
Endpoint URLWithEndpoint(endpoint)BLEEMEO_API_URLhttps://api.bleemeo.com
Initial refresh tokenWithInitialOAuthRefreshToken(token)BLEEMEO_OAUTH_INITIAL_REFRESH_TOKENNone. This is an alternative to username & password credentials.
HTTP clientWithHTTPClient(client)-None. This option allow to customize behavior of the HTTP client.
New OAuth token callbackWithNewOAuthTokenCallback(callback)-None. This option allow to get access to refresh token, useful for initial refresh token option.
Throttle max auto retry delayWithThrottleMaxAutoRetryDelay(delay)-1 minute.

# Packages

No description provided by the author

# Functions

JSONReaderFrom marshals the given content to JSON, and returns a reader to the marshaled data.
NewClient initializes a Bleemeo API client with the given options.
WithBleemeoAccountHeader will make the client include the given account ID in the X-Bleemeo-Account request header.
WithConfigurationFromEnv will make the client retrieve and use configuration options defined in environment variables, such as - credentials: "BLEEMEO_USER" & "BLEEMEO_PASSWORD" - Bleemeo account ID: "BLEEMEO_ACCOUNT_ID" - OAuth client ID/secret: "BLEEMEO_OAUTH_CLIENT_ID" & "BLEEMEO_OAUTH_CLIENT_SECRET" - API URL: "BLEEMEO_API_URL" - Initial refresh token: "BLEEMEO_OAUTH_INITIAL_REFRESH_TOKEN".
WithCredentials will make the client use the given credentials.
WithEndpoint will make the client use the given endpoint over the default one.
WithHTTPClient will make the client execute requests with the given [http.Client].
WithInitialOAuthRefreshToken will make the client prefer the given refresh token over regular user/password credentials for authenticating against the API.
WithNewOAuthTokenCallback defines the given function as the one to be called when a new OAuth token is retrieved.
WithOAuthClient will make the client use the given OAuth client ID/secret over the default one.
WithThrottleMaxAutoRetryDelay defines the delay under which throttled requests are automatically resent.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
nolint: revive,stylecheck,gofmt,gofumpt,goimports.
nolint: revive,stylecheck,gofmt,gofumpt,goimports.
nolint: revive,stylecheck,gofmt,gofumpt,goimports.
nolint: revive,stylecheck,gofmt,gofumpt,goimports.
nolint: revive,stylecheck,gofmt,gofumpt,goimports.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
Available resources on the Bleemeo API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrNoAuthMeanProvided is returned when the client has no way to retrieve an OAuth token.
ErrResourceNotFound is returned when the resource with the specified ID doesn't exist (HTTP status 404).
ErrTokenIsRefreshOnly is returned when trying to request a new token, but credentials haven't been provided.
ErrTokenRevoke is returned when the logout operation has not been completed successfully.

# Structs

APIError represents an error returned by the Bleemeo API, when the StatusCode is in the 4xx or 5xx range.
An AuthError holds an error due to unspecified or invalid credentials.
Client is a helper to interact with the Bleemeo API, providing methods to retrieve, list, create, update and delete resources.
JSONMarshalError represents an error that occurred during the serialization of data to JSON.
JSONUnmarshalError represents an error that occurred during the deserialization of data from JSON.
No description provided by the author
A ThrottleError is returned when the API received too much requests from the client.

# Interfaces

An Iterator allows browsing all the resources of a specific kind, optionally matching specified parameters, and automatically fetching the next page when needed.

# Type aliases

No description provided by the author
A ClientOption can be used to customize the [Client].
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
JSONErrorDataKind indicates the type of data whose conversion failed.
No description provided by the author
No description provided by the author
A Resource represents a route to a model on the Bleemeo API.
No description provided by the author
No description provided by the author