Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorOutput(res http.ResponseWriter, req *http.Request, resCode ResCode, err error)
- func GetConnection(connProfile *api.ConnectionProfile, participant *api.Participant, ...) (*api.NetworkConnection, error)
- func GetExeFolder() string
- func GetRequest(req *http.Request, reqBody Request, useDiscovery bool, ...) (*api.NetworkConnection, error)
- func GetTmpFolder() string
- func HandleBlockEvent(wsConn *websocket.Conn) error
- func HandleBlockQuery(res http.ResponseWriter, req *http.Request)
- func HandleBlockQueryAny(res http.ResponseWriter, req *http.Request)
- func HandleChaincodeExecute(res http.ResponseWriter, req *http.Request)
- func HandleChaincodeInstall(res http.ResponseWriter, req *http.Request)
- func HandleChaincodeInstantiate(res http.ResponseWriter, req *http.Request)
- func HandleChaincodeUpgrade(res http.ResponseWriter, req *http.Request)
- func HandleCreateChannel(res http.ResponseWriter, req *http.Request)
- func HandleJoinChannel(res http.ResponseWriter, req *http.Request)
- func HandleLedgerQuery(res http.ResponseWriter, req *http.Request)
- func HandleNetworkDiscover(res http.ResponseWriter, req *http.Request)
- func HandleNetworkRefresh(res http.ResponseWriter, req *http.Request)
- func HandlePeerDetails(res http.ResponseWriter, req *http.Request)
- func HandleRoot(res http.ResponseWriter, req *http.Request)
- func JsonOutput(res http.ResponseWriter, req *http.Request, result map[string]interface{})
- func NewConnection(connProfile *api.ConnectionProfile, participant *api.Participant, ...) (*api.NetworkConnection, error)
- func PlainOutput(res http.ResponseWriter, req *http.Request, content []byte)
- func ResultOutput(res http.ResponseWriter, req *http.Request, result map[string]interface{})
- func SetHeader(res http.ResponseWriter, req *http.Request, addHeaders map[string]string)
- type BaseRequest
- type BlockEventResult
- type BlockQueryAnyReq
- type BlockQueryReq
- type ChaincodeExecuteReq
- type ChaincodeInstallReq
- type ChaincodeInstantiateReq
- type ConnSession
- type CreateChannelReq
- type EventReq
- type HTTPHandler
- type JoinChannelReq
- type LedgerQueryReq
- type NetworkDiscoverReq
- type NetworkRefreshReq
- type PeerDetailsReq
- type Request
- type RequestConnection
- type RequestOption
- type RequestOptionFunc
- type ResCode
- type WSHandler
Constants ¶
const ( RES_CODE_ERR_INTERNAL = ResCode(500) RES_CODE_OK = ResCode(200) )
const ( // WSPingInterval interval of ping WSPingInterval = time.Second * 10 // WSWriteDeadline deadline time of write WSWriteDeadline = time.Second * 10 )
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 ¶
var ExeFolder = GetExeFolder()
Functions ¶
func ErrorOutput ¶
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 HandleBlockEvent ¶
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{})
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.
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 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.