service

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RES_CODE_ERR_INTERNAL = ResCode(500)
	RES_CODE_OK           = ResCode(200)
)
View Source
const (
	// WSPingInterval interval of ping
	WSPingInterval = time.Second * 10
	// WSWriteDeadline deadline time of write
	WSWriteDeadline = time.Second * 10
)
View Source
const (
	// ConnMonitorInterval  to check the connection every interval.
	ConnMonitorInterval = time.Second * 30
	// ConnInactiveLongest  the connection will be closed and removed if be not actived for longer than the inactive time.
	ConnInactiveLongest = time.Minute * 10
)

Variables

View Source
var ExeFolder = GetExeFolder()

Functions

func ErrorOutput

func ErrorOutput(res http.ResponseWriter, req *http.Request, resCode ResCode, err error)

TODO all function should has return value.

func GetConnection

func GetConnection(connProfile *api.ConnectionProfile, participant *api.Participant, useDiscovery bool) (*api.NetworkConnection, error)

GetConnection get connection from session, might be existing or new.

func GetExeFolder

func GetExeFolder() string

GetExeFolder to get the folder of current executable binary file.

func GetRequest

func GetRequest(req *http.Request, reqBody Request, useDiscovery bool, options ...RequestOptionFunc) (*api.NetworkConnection, error)

GetRequest get request from http TODO to use GetRequest for all services, and, all connections are not closed after calling, to hold connection in session.

func GetTmpFolder

func GetTmpFolder() string

GetTmpFolder to get temp folder.

func HandleBlockEvent

func HandleBlockEvent(wsConn *websocket.Conn) error

HandleBlockEvent handle event

func HandleBlockQuery

func HandleBlockQuery(res http.ResponseWriter, req *http.Request)

HandleBlockQuery to query blocks of a ledger

func HandleBlockQueryAny

func HandleBlockQueryAny(res http.ResponseWriter, req *http.Request)

HandleBlockQueryAny to query a block of a ledger by any possible kind of key

func HandleChaincodeExecute

func HandleChaincodeExecute(res http.ResponseWriter, req *http.Request)

HandleChaincodeExecute to execute a chaincode

func HandleChaincodeInstall

func HandleChaincodeInstall(res http.ResponseWriter, req *http.Request)

HandleChaincodeInstall to install a chaincode

func HandleChaincodeInstantiate

func HandleChaincodeInstantiate(res http.ResponseWriter, req *http.Request)

HandleChaincodeInstantiate to instantiate a chaincode.

func HandleChaincodeUpgrade

func HandleChaincodeUpgrade(res http.ResponseWriter, req *http.Request)

HandleChaincodeUpgrade to upgrade chaincode.

func HandleCreateChannel

func HandleCreateChannel(res http.ResponseWriter, req *http.Request)

HandleCreateChannel to create a channle via orderer

func HandleJoinChannel

func HandleJoinChannel(res http.ResponseWriter, req *http.Request)

HandleJoinChannel for peer to join a channel

func HandleLedgerQuery

func HandleLedgerQuery(res http.ResponseWriter, req *http.Request)

HandleLedgerQuery to query a ledger of a channel

func HandleNetworkDiscover

func HandleNetworkDiscover(res http.ResponseWriter, req *http.Request)

HandleNetworkDiscover to discover all network

func HandleNetworkRefresh

func HandleNetworkRefresh(res http.ResponseWriter, req *http.Request)

HandleNetworkRefresh to discover all network

func HandlePeerDetails

func HandlePeerDetails(res http.ResponseWriter, req *http.Request)

HandlePeerDetails for peer details

func HandleRoot

func HandleRoot(res http.ResponseWriter, req *http.Request)

func JsonOutput

func JsonOutput(res http.ResponseWriter, req *http.Request, result map[string]interface{})

func NewConnection

func NewConnection(connProfile *api.ConnectionProfile, participant *api.Participant, useDiscovery bool) (*api.NetworkConnection, error)

NewConnection create connection and then store it into session.

func PlainOutput

func PlainOutput(res http.ResponseWriter, req *http.Request, content []byte)

func ResultOutput

func ResultOutput(res http.ResponseWriter, req *http.Request, result map[string]interface{})

func SetHeader

func SetHeader(res http.ResponseWriter, req *http.Request, addHeaders map[string]string)

Types

type BaseRequest

type BaseRequest struct {
	Connection *RequestConnection `json:"connection"`
}

func (*BaseRequest) GetReqConn

func (req *BaseRequest) GetReqConn() *RequestConnection

GetReqConn interface function

type BlockEventResult

type BlockEventResult struct {
	Number     uint64 `json:"number"`
	TXNumber   int    `json:"TXNumber"`
	UpdateTime int64  `json:"updateTime"`
	SourceURL  string `json:"sourceURL"`
}

BlockEventResult block event result

type BlockQueryAnyReq

type BlockQueryAnyReq struct {
	BaseRequest
	ChannelID string   `json:"channelID"`
	Targets   []string `json:"targets"`
	QueryKey  string   `json:"queryKey"`
}

BlockQueryAnyReq to query block with any: tx id, block hash, block number

type BlockQueryReq

type BlockQueryReq struct {
	BaseRequest
	ChannelID string   `json:"channelID"`
	Targets   []string `json:"targets"`
	Begin     uint64   `json:"begin"`
	Len       uint64   `json:"len"`
}

BlockQueryReq to query blocks

type ChaincodeExecuteReq

type ChaincodeExecuteReq struct {
	BaseRequest
	Chaincode    api.Chaincode `json:"chaincode"`
	ActionType   string        `json:"actionType"`
	FunctionName string        `json:"functionName"`
	Arguments    []string      `json:"arguments"`
	Targets      []string      `json:"targets"`
}

ChaincodeExecuteReq to execute a chaincode

type ChaincodeInstallReq

type ChaincodeInstallReq struct {
	BaseRequest
	Chaincode     api.Chaincode `json:"chaincode"`
	PackageFormat string        `json:"packageFormat"`
	Targets       []string      `json:"targets"`
}

ChaincodeInstallReq use fields instead of anonlymous fields, to have a more clear structure.

type ChaincodeInstantiateReq

type ChaincodeInstantiateReq struct {
	BaseRequest
	Chaincode api.Chaincode `json:"chaincode"`
	Target    string        `json:"target"`
	Orderer   string        `json:"orderer"`
	IsUpgrade bool          `json:"isUpgrade"`
}

ChaincodeInstantiateReq for instantiate a chaincode.

type ConnSession

type ConnSession struct {
	Connections map[string]*api.NetworkConnection
	sync.RWMutex
}

ConnSession to store all connections. TODO to have NetworkConnection with lock. ***

type CreateChannelReq

type CreateChannelReq struct {
	BaseRequest
	TxContent []byte `json:"txContent"`
	Orderer   string `json:"orderer"`
}

CreateChannelReq to create a channel

type EventReq

type EventReq struct {
	BaseRequest
	ChannelID string `json:"channelID"`
}

EventReq use fields instead of anonlymous fields, to have a more clear structure.

type HTTPHandler

type HTTPHandler func(res http.ResponseWriter, req *http.Request)

HTTPHandler To handle all incoming http request

func Post

func Post(hh HTTPHandler) HTTPHandler

Post to return HTTPHandler only process post method.

func WS

func WS(wsh WSHandler) HTTPHandler

WS to return websocket handler

type JoinChannelReq

type JoinChannelReq struct {
	BaseRequest
	ChannelID string   `json:"channelID"`
	Targets   []string `json:"targets"`
	Orderer   string   `json:"orderer"`
}

JoinChannelReq to join a channel

type LedgerQueryReq

type LedgerQueryReq struct {
	BaseRequest
	ChannelID string   `json:"channelID"`
	Targets   []string `json:"targets"`
}

LedgerQueryReq to query a ledger

type NetworkDiscoverReq

type NetworkDiscoverReq struct {
	BaseRequest
}

NetworkDiscoverReq discover request

type NetworkRefreshReq

type NetworkRefreshReq struct {
	BaseRequest
}

NetworkRefreshReq discover request. Same with NetworkDiscoverReq, but it will includes refresh=true.

type PeerDetailsReq

type PeerDetailsReq struct {
	BaseRequest
	Target   string   `json:"target"`
	Channels []string `json:"channels"`
}

PeerDetailsReq to get details of a peer

type Request

type Request interface {
	GetReqConn() *RequestConnection
}

type RequestConnection

type RequestConnection struct {
	Label         string `json:"label"`
	MSPID         string `json:"MSPID"`
	CertContent   string `json:"certContent"`
	PrvKeyContent string `json:"prvKeyContent"`
	ConnProfile   string `json:"connProfile"`
}

RequestConnection request with connection

type RequestOption

type RequestOption struct {
	Refresh bool
}

RequestOption optios for request.

type RequestOptionFunc

type RequestOptionFunc func(opt *RequestOption) error

RequestOptionFunc to handle the request option

func WithRefresh

func WithRefresh(refresh bool) RequestOptionFunc

WithRefresh only retrieve details of the peer.

type ResCode

type ResCode int32

type WSHandler

type WSHandler func(wsConn *websocket.Conn) error

WSHandler To handle all incoming http request

Jump to

Keyboard shortcuts

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