transports

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FieldID is the id field for most models
	FieldID = "id"

	// FieldUsername is the username field for login
	FieldUsername = "username"

	// FieldPassword is the password field for login
	FieldPassword = "password"

	// FieldSubscriptionID is the subscription id field
	FieldSubscriptionID = "id"

	// FieldUserAgent is the field for storing the user agent
	FieldUserAgent = "user_agent"
)
View Source
const JungleBusClientVersion = "v0.1.0"

JungleBusClientVersion is the version of the client

View Source
const JungleBusUserAgent = "JungleBus: go-client " + JungleBusClientVersion

JungleBusUserAgent the user agent sent to the jungle bus server

Variables

View Source
var ErrFailedLogin = errors.New("failed to login to server")
View Source
var ErrNoClientSet = errors.New("no transport client set")

ErrNoClientSet is when no client is set

Functions

This section is empty.

Types

type AddressService

type AddressService interface {
	GetAddressTransactions(ctx context.Context, address string) ([]*models.Address, error)
	GetAddressTransactionDetails(ctx context.Context, address string) ([]*models.Transaction, error)
}

AddressService is the address related requests

type BlockHeaderService

type BlockHeaderService interface {
	GetBlockHeader(ctx context.Context, block string) (*models.BlockHeader, error)
	GetBlockHeaders(ctx context.Context, fromBlock string, limit uint) ([]*models.BlockHeader, error)
}

BlockHeaderService is the block header related requests

type Client

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

Client is the transport client

type ClientOps

type ClientOps func(c *Client)

ClientOps are the client options functions

func WithDebugging

func WithDebugging(debug bool) ClientOps

WithDebugging will set whether to turn debugging on

func WithHTTP

func WithHTTP(serverURL string) ClientOps

WithHTTP will overwrite the default client with a custom client

func WithHTTPClient

func WithHTTPClient(serverURL string, httpClient *http.Client) ClientOps

WithHTTPClient will overwrite the default client with a custom client

func WithSSL

func WithSSL(useSSL bool) ClientOps

WithSSL will set whether to use SSL in all communications

func WithToken

func WithToken(token string) ClientOps

WithToken will set the token to use in all requests

func WithVersion

func WithVersion(version string) ClientOps

WithVersion will set the version of the API to use

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

LoginResponse response from server on login or token refresh

type TransactionService

type TransactionService interface {
	GetTransaction(ctx context.Context, txID string) (*models.Transaction, error)
}

TransactionService is the transaction related requests

type TransportHTTP

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

TransportHTTP is the struct for HTTP

func (*TransportHTTP) GetAddressTransactionDetails

func (h *TransportHTTP) GetAddressTransactionDetails(ctx context.Context, address string) (transactions []*models.Transaction, err error)

GetAddressTransactionDetails will get all transactions related to the given address

func (*TransportHTTP) GetAddressTransactions

func (h *TransportHTTP) GetAddressTransactions(ctx context.Context, address string) (addr []*models.Address, err error)

GetAddressTransactions will get the metadata of all transaction related to the given address

func (*TransportHTTP) GetBlockHeader

func (h *TransportHTTP) GetBlockHeader(ctx context.Context, block string) (blockHeader *models.BlockHeader, err error)

GetBlockHeader will get the given block header details Can pass either the block hash or the block height (as a string)

func (*TransportHTTP) GetBlockHeaders

func (h *TransportHTTP) GetBlockHeaders(ctx context.Context, fromBlock string, limit uint) (blockHeaders []*models.BlockHeader, err error)

GetBlockHeaders will get all block headers from the given block, limited by limit Can pass either the block hash or the block height (as a string)

func (*TransportHTTP) GetServerURL

func (h *TransportHTTP) GetServerURL() string

GetServerURL get the server URL for this transport

func (*TransportHTTP) GetSubscriptionToken

func (h *TransportHTTP) GetSubscriptionToken(ctx context.Context, subscriptionID string) (string, error)

GetSubscriptionToken gets a token based on the subscription ID

func (*TransportHTTP) GetToken

func (h *TransportHTTP) GetToken() string

GetToken gets the token to use for all requests

func (*TransportHTTP) GetTransaction

func (h *TransportHTTP) GetTransaction(ctx context.Context, txID string) (transaction *models.Transaction, err error)

GetTransaction will get a transaction by ID

func (*TransportHTTP) IsDebug

func (h *TransportHTTP) IsDebug() bool

IsDebug return the debugging status

func (*TransportHTTP) IsSSL

func (h *TransportHTTP) IsSSL() bool

IsSSL return the SSL status

func (*TransportHTTP) Login

func (h *TransportHTTP) Login(ctx context.Context, username string, password string) error

func (*TransportHTTP) RefreshToken

func (h *TransportHTTP) RefreshToken(ctx context.Context) (string, error)

RefreshToken gets a new token to use for all requests

func (*TransportHTTP) SetDebug

func (h *TransportHTTP) SetDebug(debug bool)

SetDebug turn the debugging on or off

func (*TransportHTTP) SetToken

func (h *TransportHTTP) SetToken(token string)

SetToken sets the token to use for all requests manually

func (*TransportHTTP) SetVersion

func (h *TransportHTTP) SetVersion(version string)

SetVersion sets the version to use for all calls

func (*TransportHTTP) UseSSL

func (h *TransportHTTP) UseSSL(useSSL bool)

UseSSL turn the SSL on or off

type TransportService

type TransportService interface {
	AddressService
	BlockHeaderService
	TransactionService
	Login(ctx context.Context, username string, password string) error
	IsDebug() bool
	SetDebug(debug bool)
	GetToken() string
	GetSubscriptionToken(ctx context.Context, subscriptionID string) (string, error)
	RefreshToken(ctx context.Context) (string, error)
	SetToken(token string)
	SetVersion(version string)
	UseSSL(useSSL bool)
	IsSSL() bool
	GetServerURL() string
}

TransportService the transport service interface

func NewTransport

func NewTransport(opts ...ClientOps) (TransportService, error)

NewTransport create a new transport service object

func NewTransportService

func NewTransportService(transportService TransportService) TransportService

NewTransportService create a new transport service interface

type TransportType

type TransportType string

TransportType the type of transport being used (http or graphql)

const (
	// JungleBusTransportHTTP uses the http transport for all jungle bus server actions
	JungleBusTransportHTTP TransportType = "http"

	// JungleBusTransportMock uses the mock transport for all jungle bus server actions
	JungleBusTransportMock TransportType = "mock"
)

Jump to

Keyboard shortcuts

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