Skip to content

gernest/resingo

Repository files navigation

resingo GoDoc Go Report CardBuild StatusCoverage Status

The unofficial golang sdk for resin.io

MAINTAINER WANTED I no longer work with resin devices, so I don't have time to put into this. If you are interested in maintaining this please let me know! Thanks.

what is resin and what is resingo?

Resin is a service that brings the benefits of linux containers to IoT. It enables iterative development, deployment and management of devices at scale. Please go to their website for more information.

Resingo, is a standard development kit for resin, that uses the Go(Golang) programming language. This library, provides nuts and bolts necessary for developers to interact with resin service using the Go programming language.

This library is full featured, well tested and well designed. If you find anything that is missing please open an issssue

This is the laundry list of things you can do.

  • Applications

  • Get all applications

  • Get application by name

  • Get application by application id

  • Create Application

  • Delete application

  • Generate application API key

  • Devices

  • Get all devices

  • Get all devices for a given device name

  • Get device by UUID

  • Get device by name

  • Get application name by device uuid

  • Check if the device is online or not

  • Get local IP address of the device

  • Remove/Delete device

  • Rename device

  • Note a device

  • Generate device UUID

  • Register device

  • Enable device url

  • Disable device url

  • Move device

  • Check device status

  • Identify device by blinkig

  • Environment

  • Device

  • Get all device environment variables

  • Create a device environment variable

  • Update device environment variable

  • Remove/Delete device environment variable

  • Application

  • Get all application environment variables

  • Create application environment variable

  • Update application environment variable

  • Remove application environment variable

  • Keys

  • Get all ssh keys

  • Get a dingle ssh key

  • Remove ssh key

  • Create ssh key

  • Os

    • Download Os Image
  • Config

  • Get all configurations

  • Logs

  • Subscribe to device logs

  • Retrieve historical logs

  • Supervisor

  • Reboot

Introduction

Installation

go get github.com/gernest/resingo

Design philosophy

Naming convention

The library covers different componets of the resin service namely device, application, os ,environment and keys.

Due to the nature of this lirary to use functions rather than attach methods to the relevant structs. We use a simple strategy of naming functions that operates for the different components. This is by adding Prefix that represent the resin component.

The following is the Prefix table that shows all the prefix used to name the functions. For example DevGetAll is a function that retrives all devices and AppGetAll is a function that retrieves all App;ications.

component function prefix
Device Dev
Application App
EnvironMent Env
Os Os
Keys Key

Functions over methods

This library favors functions to provide functionality that interact with resin. All this functions accepts Context as the first argument, and can optionally accepts other arguments which are function specific( Note that this Context is defined in this libary, don't mistook it for the context.Context).

The reason behind this is to provide composability and making the codebase clean. Also it is much easier for testing.

Usage

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gernest/resingo"
)

func main() {

	// We need the context from which we will be talking to the resin API
	ctx := &resingo.Context{
		Client: &http.Client{},
		Config: &resingo.Config{
			Username: "Your resing username",
			Password: "your resubn password",
		},
	}

	/// There are two ways to authenticate the context ctx.

	// Authenticate with credentials i.e Username and password
	err := resingo.Login(ctx, resingo.Credentials)
	if err != nil {
		log.Fatal(err)
	}

	// Or using authentication token, which you can easily find on your resin
	// dashboard
	err = resingo.Login(ctx, resingo.AuthToken, "Tour authentication token goes here")
	if err != nil {
		log.Fatal(err)
	}

	// Now the ctx is authenticated you can pass it as the first arument to any
	// resingo API function.
	//
	// The ctx is safe for concurrent use

	// Get All your applications
	apps, err := resingo.AppGetAll(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for _, a := range apps {
		fmt.Println(*a)
	}
}

Contributing

This requires go1.7+

Running tests will require a valid resin account . You need to set the following environment variables before running the make command.

export RESINTEST_EMAIL=
export RESINTEST_PASSWORD=
export RESINTEST_USERNAME=
export RESINTEST_REALDEVICE_UUID=

The names are self explanatory. To avoid typing them all the time, you can write them into a a file named .env which stays at the root of this project, the test script will automatically source it for you.

All contributions are welcome.

Author

twitter @gernesti

Licence

MIT

About

[UNMAINTAINED] Unofficial golang sdk for resin.io

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages