flareio package - github.com/Flared/go-flareio - Go Packages

flareio

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 8 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(
		"/leaksdb/v2/sources",
	)
	if err != nil {
		fmt.Printf("failed to get sources: %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 sources: %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

func (*ApiClient) GenerateToken

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

func (*ApiClient) Get

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

func (*ApiClient) IterGet added in v0.2.0

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

func (*ApiClient) Post

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

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 *http.Response
	Next     string
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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