flareio

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 9 Imported by: 0

README

go-flareio

Go Reference

flareio is a light Flare API SDK that wraps around net/http.Client and automatically manages authentication.

It exposes methods that are similar to net/http.Client with the exception that they accept paths as parameters instead of full URLs.

Usage examples and use cases are documented in the Flare API documentation.

Contributing

  • make test will run tests
  • make format format will format the code
  • make lint will run typechecking + linting

Basic Usage

package main

import (
	"fmt"
	"io"
	"os"

	"github.com/Flared/go-flareio"
)

func main() {
	client := flareio.NewApiClient(
		os.Getenv("FLARE_API_KEY"),
	)
	resp, err := client.Get(
		"/tokens/test", nil,
	)
	if err != nil {
		fmt.Printf("failed to test token: %s\n", err)
		os.Exit(1)
	}
	defer resp.Body.Close()
	if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
		fmt.Printf("failed to print response: %s\n", err)
		os.Exit(1)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

type ApiClient struct {
	// contains filtered or unexported fields
}

func NewApiClient

func NewApiClient(
	apiKey string,
	optionFns ...ApiClientOption,
) *ApiClient

NewApiClient can be used to create a new ApiClient instance.

func (*ApiClient) GenerateToken

func (client *ApiClient) GenerateToken() (string, error)

GenerateToken creates a Flare API token using the API Client's API key.

func (*ApiClient) Get

func (client *ApiClient) Get(path string, params *url.Values) (*http.Response, error)

Get peforms an authenticated GET request at the given path. Includes params in the query string.

func (*ApiClient) IterGet added in v0.2.0

func (client *ApiClient) IterGet(
	path string,
	params *url.Values,
) iter.Seq2[*IterResult, error]

IterGet allows to iterate over responses for an API endpoint that supports the Flare standard paging pattern.

func (*ApiClient) IterPostJson added in v0.4.0

func (client *ApiClient) IterPostJson(
	path string,
	params *url.Values,
	body map[string]interface{},
) iter.Seq2[*IterResult, error]

IterPostJson allows to iterate over responses for an API endpoint that supports the Flare standard paging pattern.

func (*ApiClient) Post

func (client *ApiClient) Post(
	path string,
	params *url.Values,
	contentType string,
	body io.Reader,
) (*http.Response, error)

Post performs an authenticated POST request at the given path. Includes params in the query string. The provided ContentType should describe the content of the body.

type ApiClientOption

type ApiClientOption func(*ApiClient)

func WithTenantId

func WithTenantId(tenantId int) ApiClientOption

WithTenantId allows configuring the tenant id.

type IterResult added in v0.2.0

type IterResult struct {
	// Response associated with the fetched page.
	//
	// The response's body must be closed.
	Response *http.Response

	// Next is the token to be used to fetch the next page.
	Next string
}

IterResult contains results for a given page.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL