connector

package module
v0.0.0-...-a1ca7c7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

dyn-connector-go

Go M2M interface to Dyn/PigrecoOS

Features

  • Stateless and stateful modes
  • Transparent Auth and tokens expiration management

Installation and usage

import "github.com/modulo-srl/dyn-connector-go"

See connector_test.go for examples.

Master Token and Auth UID are authorization constants that could be obtained from PigrecoOS services.

Session token, used with the only get/set callback required by the Connector, must to be saved on a persistent storage, for example a file or a DB.

For Operation and related parameters please refer to PigrecoOS API section.


Copyright 2020 Modulo srl - Licensed under the Apache license

Documentation

Index

Constants

View Source
const (
	URLApi         = "/api/"
	URLAccessToken = "auth/token"
)
View Source
const (
	ErrorInternal        = "internal"         // Connector error
	ErrorNetwork         = "network"          // Network error
	ErrorInvalidResponse = "invalid_response" // Server response cannot be decoded
	ErrorUnauthorized    = "unauthorized"     // Auth error
)

ResponseError.ID

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

type Connector struct {
	Debug bool
	// contains filtered or unexported fields
}

Connector object

func NewConnector

func NewConnector(host, clientID, clientSecret string, persistor TokensPersistor) *Connector

NewConnector make a new Dyn Connector

func (*Connector) Send

func (c *Connector) Send(operation string, dataSend, dataReceive interface{}) *ResponseError

Send operation request, passing data and receiving custom data types

func (*Connector) SetDebug

func (c *Connector) SetDebug(enableDebug bool, customHTTPheader map[string]string, protocolByHost bool)

SetDebug enable or disable debug and internal params

func (*Connector) SetUserAgent

func (c *Connector) SetUserAgent(userAgent string)

SetUserAgent optionally sets the User-Agent header for future requests.

type ResponseError

type ResponseError struct {
	ID       string `json:"error"`
	Reason   string `json:"error_description"`
	HTTPCode int
}

ResponseError with error codes

func (*ResponseError) Error

func (err *ResponseError) Error() string

type TokensPersistor

type TokensPersistor interface {
	GetAccessToken() string
	SetAccessToken(string)
}

TokensPersistor mantains the tokens persistent

Jump to

Keyboard shortcuts

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