api

package
v0.0.0-...-4aff0ea Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

README

Seashell API Client

This directory contains the api package which aims at providing programmatic access to Seashell's HTTP API.

Documentation

...

Usage

package main

import "github.com/seashell/agent/api"

func main() {
	// Get a new client
	client, err := api.NewClient(api.DefaultConfig())
	if err != nil {
		panic(err)
	}   
	
	// Get a handle to the networks API
	networks := client.Networks()

	// Create a new network
	n := &api.Network{
		Name: "my-new-network",
		IPAddressRange: "10.1.1.0/24"
	}

	id, err := networks.Create(context.Background(), n)
	if err != nil {
		panic(err)
	}

    	...
}

To run this example, start a Seashell server:

seashell agent --server

Copy the code above into a file such as main.go, and run it.

After running the code, you can also view the values in the Seashell UI on your local machine at http://localhost:8080/ui/

Documentation

Index

Constants

View Source
const (
	// DefaultAddress is the default Seashell server address.
	DefaultAddress = "http://127.0.0.1:8123"

	// DefaultTimeout is the default request timeout.
	DefaultTimeout = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides a client to the Seashell API

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new Seashell API client

func (*Client) Devices

func (c *Client) Devices() *Devices

Devices returns a handle on the nodes endpoints.

func (*Client) WithHeaders

func (c *Client) WithHeaders(headers map[string]string) *Client

WithHeaders returns a new Client that will use the specified headers in addition to those present in the original client in any future request. In case of a collision, the header in the original client will be overwritten.

type Config

type Config struct {
	// URL of the Seashell server (e.g. http://127.0.0.1:8080).
	Address string

	// Token to be used for authentication.
	Token string

	// Request timeout.
	Timeout time.Duration
}

Config contains configurations for Seashell's API client.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration for Seashell's API client.

func (*Config) Merge

func (c *Config) Merge(b *Config) *Config

Merge merges two API client configurations.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configurations contained wihin the Config struct.

type Devices

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

Devices is a handle to the devices API

func (*Devices) GetDeviceToken

GetDeviceToken :

func (*Devices) SyncDevice

SyncDevice :

Jump to

Keyboard shortcuts

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