goclient

package module
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2022 License: MIT Imports: 12 Imported by: 13

README

GoClient

This is the official API client, written in Go, for accessing the Flow Swiss and Cloudbit APIs. Our API Documentation can be found at my.flow.swiss/#/doc or my.cloudbit.ch/#/doc.

Installation

go get github.com/flowswiss/goclient

Example

package main

import (
  "context"
  "fmt"

  "github.com/flowswiss/goclient"
  "github.com/flowswiss/goclient/compute"
)

func main() {
  client := goclient.NewClient(goclient.WithToken("your-application-token"))
  
  service := compute.NewServerService(client)

  res, err := service.List(context.Background(), goclient.Cursor{
    Page:    1,
    PerPage: 5,
  })

  if err != nil {
    fmt.Println("error listing servers: ", err)
  }

  for _, server := range res.Items {
    fmt.Println("found server with id ", server.Id)
  }
}

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongContentType = errors.New("wrong content type")

Functions

func Join

func Join(parts ...interface{}) (p string)

Types

type APIError added in v0.2.1

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

func (APIError) Error added in v0.2.1

func (a APIError) Error() string

func (APIError) RequestID added in v0.2.1

func (a APIError) RequestID() string

func (APIError) Response added in v0.2.1

func (a APIError) Response() *http.Response

type AuthTransport

type AuthTransport struct {
	Token string
	Base  http.RoundTripper
}

func (AuthTransport) RoundTrip

func (t AuthTransport) RoundTrip(request *http.Request) (*http.Response, error)

type Client

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

func NewClient

func NewClient(options ...Option) Client

func (Client) Create

func (c Client) Create(ctx context.Context, path string, body interface{}, dest interface{}) error

func (Client) Delete

func (c Client) Delete(ctx context.Context, path string) error

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, val interface{}) (*http.Response, error)

func (Client) Get

func (c Client) Get(ctx context.Context, path string, dest interface{}) error

func (Client) List

func (c Client) List(ctx context.Context, path string, cursor Cursor, dest interface{}) (Pagination, error)

func (Client) NewRequest

func (c Client) NewRequest(method string, path string, body interface{}) (*http.Request, error)

func (Client) Set added in v0.2.4

func (c Client) Set(ctx context.Context, path string, body interface{}, dest interface{}) error

func (Client) Update

func (c Client) Update(ctx context.Context, path string, body interface{}, dest interface{}) error

func (Client) With

func (c Client) With(options ...Option) Client

type Cursor

type Cursor struct {
	// Number of the current page
	Page int `url:"page,omitempty"`
	// Maximum number of items per page
	PerPage int `url:"per_page,omitempty"`
	// If set to 1, disables pagination entirely so that all entities will be returned
	NoFilter int `url:"no_filter,omitempty"`
}

func (Cursor) Next

func (c Cursor) Next() Cursor
type Links struct {
	// URL to the first page
	First string
	// URL to the last page
	Last string
	// URL to the current page
	Current string
	// URL to the previous page
	Prev string
	// URL to the next page
	Next string
}

Provides direct links to the individual pages

type Option

type Option func(*Client)

func WithBase

func WithBase(base string) Option

func WithHTTPClientOption added in v0.2.1

func WithHTTPClientOption(opt func(*http.Client)) Option

func WithToken

func WithToken(token string) Option

func WithUserAgent

func WithUserAgent(userAgent string) Option

type Pagination

type Pagination struct {
	// Cursor of the current request
	Cursor
	// Number of items on the current page
	ItemCount int
	// Total number of items
	TotalCount int
	// Total number of pages
	TotalPages int
	// Direct links to the individual pages
	Links Links
}

func ParsePagination

func ParsePagination(header http.Header) Pagination

Parses the pagination headers from the given http response.

func (Pagination) HasMore

func (p Pagination) HasMore() bool

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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