rpc

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBodyBytes controls the maximum number of bytes the
	// server will read parsing the request body.
	MaxBodyBytes = int64(1000000) // 1MB
)

Variables

View Source
var (

	// RegexpInt 整数正则
	RegexpInt = regexp.MustCompile(`^-?[0-9]+$`)
	// RegexpHex 16进制正则
	RegexpHex = regexp.MustCompile(`^(?i)[a-f0-9]+$`)
	// RegexpEmail 正则
	RegexpEmail = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`)
	// RegexpAddress 正则
	RegexpAddress = regexp.MustCompile(`^(?i)[a-z0-9]{25,34}$`)
	// RegexpHost 正则
	RegexpHost = regexp.MustCompile(`^(?i)(` + domain + `)$`)
)

Functions

func GetParam

func GetParam(r *http.Request, param string) string

GetParam 获取指定参数

func GetParamByteSlice

func GetParamByteSlice(r *http.Request, param string) ([]byte, error)

GetParamByteSlice 获取指定字节切片

func GetParamFloat64

func GetParamFloat64(r *http.Request, param string) (float64, error)

GetParamFloat64 获取指定参数

func GetParamInt32

func GetParamInt32(r *http.Request, param string) (int32, error)

GetParamInt32 获取指定参数

func GetParamInt64

func GetParamInt64(r *http.Request, param string) (int64, error)

GetParamInt64 获取指定参数

func GetParamRegexp

func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error)

GetParamRegexp 获取指定参数

func GetParamUint

func GetParamUint(r *http.Request, param string) (uint, error)

GetParamUint 获取指定参数

func GetParamUint64

func GetParamUint64(r *http.Request, param string) (uint64, error)

GetParamUint64 获取指定参数

func RecoverAndLogHandler

func RecoverAndLogHandler(handler http.Handler) http.Handler

RecoverAndLogHandler Wraps an HTTP handler, adding error logging. If the inner function panics, the outer function recovers, logs, sends an HTTP 500 error response.

func StartHTTPAndTLSServer

func StartHTTPAndTLSServer(
	listenAddr string,
	handler http.Handler,
	certFile, keyFile string,
	config Config,
) (listener net.Listener, err error)

StartHTTPAndTLSServer starts an HTTPS server on listenAddr with the given handler. It wraps handler with RecoverAndLogHandler.

func StartHTTPServer

func StartHTTPServer(
	listenAddr string,
	handler http.Handler,
	config Config,
) (listener net.Listener, err error)

StartHTTPServer starts an HTTP server on listenAddr with the given handler. It wraps handler with RecoverAndLogHandler.

func WriteRPCResponseHTTP

func WriteRPCResponseHTTP(w http.ResponseWriter, res trtypes.RPCResponse)

WriteRPCResponseHTTP write rpc response

func WriteRPCResponseHTTPError

func WriteRPCResponseHTTPError(
	w http.ResponseWriter,
	httpCode int,
	res trtypes.RPCResponse,
)

WriteRPCResponseHTTPError write rpc response error

Types

type Config

type Config struct {
	MaxOpenConnections int
}

Config is an RPC server configuration.

type RequestHandler

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

RequestHandler handle rpc request

func NewRequestHandler

func NewRequestHandler(h *tmtypes.EventBus, p *pool.TxPool) *RequestHandler

NewRequestHandler new a rpc request handler

func (RequestHandler) ABCIQuery

func (s RequestHandler) ABCIQuery(path string, data cmn.HexBytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error)

ABCIQuery 交易、交易序号查询。

func (RequestHandler) BroadcastTxSync

func (s RequestHandler) BroadcastTxSync(tx tmttypes.Tx) (*ctypes.ResultBroadcastTx, error)

BroadcastTxSync 广播交易。

func (RequestHandler) Health

func (s RequestHandler) Health() (*ctypes.ResultHealth, error)

Health health check

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	Status int
	http.ResponseWriter
}

ResponseWriterWrapper Remember the status for logging

func (*ResponseWriterWrapper) Hijack

Hijack implements http.Hijacker

func (*ResponseWriterWrapper) WriteHeader

func (w *ResponseWriterWrapper) WriteHeader(status int)

WriteHeader write header

Jump to

Keyboard shortcuts

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