api

package
v0.0.0-...-e54d674 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Rest *Rest
	Ws   *Websocket
}

func NewAPI

func NewAPI(conf *APIConfig) *API

func (*API) Start

func (api *API) Start()

type APIConfig

type APIConfig struct {
	ListenREST string
	ListenWS   string
	Actions    []*Action
}

func (*APIConfig) AddAction

func (apiConf *APIConfig) AddAction(action *Action)

type Action

type Action struct {
	HandlerREST func(w rest.ResponseWriter, r *rest.Request)
	HandlerWS   func(c *Client, r *MsgWsRequest)
	// contains filtered or unexported fields
}

func NewGet

func NewGet(key string, handler func(w rest.ResponseWriter, r *rest.Request)) *Action

func NewPOST

func NewPOST(key string, handler func(w rest.ResponseWriter, r *rest.Request)) *Action

func NewWatch

func NewWatch(key string, handler func(c *Client, r *MsgWsRequest)) *Action

type Client

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

func (*Client) Conn

func (client *Client) Conn() *websocket.Conn

func (*Client) ID

func (client *Client) ID() string

func (*Client) Ping

func (client *Client) Ping(writeWait time.Duration) error

func (*Client) Send

func (client *Client) Send(message []byte) error

func (*Client) SendJSON

func (client *Client) SendJSON(message interface{}) error

func (*Client) SetMsgHandlers

func (client *Client) SetMsgHandlers(handler func(c *Client, msg []byte), onError func(c *Client))

type MsgWSResponse

type MsgWSResponse struct {
	Action  string      `json:"action"`
	ReqID   string      `json:"reqid"`
	Result  bool        `json:"result"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func NewErrorResponse

func NewErrorResponse(action string, message string) MsgWSResponse

func NewSuccessResponse

func NewSuccessResponse(action string, message string, data interface{}) MsgWSResponse

type MsgWsRequest

type MsgWsRequest struct {
	Action string      `json:"action"`
	ReqID  string      `json:"reqid"`
	Params interface{} `json:"params"`
}

type Params

type Params struct {
	Address   string `json:"address"`
	Txid      string `json:"txid"`
	Hex       string `json:"hex"`
	Type      string `json:"type"`
	Mempool   bool   `json:"mempool"`
	NoDetails bool   `json:"nodetails"`
	TimeFrom  int64  `json:"time_from"`
	TimeTo    int64  `json:"time_to"`
}

type PubSub

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

func NewPubSub

func NewPubSub() *PubSub

func (*PubSub) AddClient

func (ps *PubSub) AddClient(c *Client) *PubSub

func (*PubSub) GetClientSubs

func (ps *PubSub) GetClientSubs(topic string, client *Client) []*Subscription

func (*PubSub) Publish

func (ps *PubSub) Publish(topic string, msg []byte)

func (*PubSub) PublishJSON

func (ps *PubSub) PublishJSON(topic string, data interface{})

func (*PubSub) PublishPing

func (ps *PubSub) PublishPing(writeWait time.Duration)

func (*PubSub) RemoveClient

func (ps *PubSub) RemoveClient(client *Client) *PubSub

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(client *Client, topic string) error

func (*PubSub) Unsubscribe

func (ps *PubSub) Unsubscribe(client *Client, topic string) *PubSub

type Resolver

type Resolver struct {
	URI            string
	Client         *http.Client
	ContextTimeout time.Duration
}

func NewResolver

func NewResolver(uri string, conns int) *Resolver

func (*Resolver) GetRequest

func (r *Resolver) GetRequest(query string, res interface{}) error

func (*Resolver) PostRequest

func (r *Resolver) PostRequest(query string, jsonBody string, res interface{}) error

func (*Resolver) SetTimeout

func (r *Resolver) SetTimeout(time time.Duration)

type Response

type Response struct {
	Action  string      `json:"action"`
	Result  bool        `json:"result"`
	Height  int64       `json:"height"`
	Message string      `json:"message"`
	Txs     interface{} `json:"txs"`
}

type Rest

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

func NewREST

func NewREST(conf *APIConfig) *Rest

func (*Rest) Start

func (re *Rest) Start()

type Subscription

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

type Websocket

type Websocket struct {
	Pubsub *PubSub
	// contains filtered or unexported fields
}

func NewWebsocket

func NewWebsocket(conf *APIConfig) *Websocket

func (*Websocket) Publish

func (ws *Websocket) Publish(topic string, data interface{})

func (*Websocket) Start

func (ws *Websocket) Start()

Jump to

Keyboard shortcuts

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