rpc

package
Version: v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: MIT Imports: 26 Imported by: 544

Documentation

Overview

Package rpc is the hprose RPC library for Golang.

Index

Constants

View Source
const (
	// Normal is default mode
	Normal = ResultMode(iota)
	// Serialized means the result is serialized
	Serialized
	// Raw means the result is the raw bytes data
	Raw
	// RawWithEndTag means the result is the raw bytes data with the end tag
	RawWithEndTag
)

Variables

View Source
var DisableGlobalCookie = false

DisableGlobalCookie is a flag to disable global cookie

View Source
var ErrClientIsAlreadyClosed = errors.New("The Client is already closed")

ErrClientIsAlreadyClosed represents a error

View Source
var ErrNotSupportMultpleProtocol = errors.New("Not support multiple protocol")

ErrNotSupportMultpleProtocol represents a error

View Source
var ErrServerIsAlreadyStarted = errors.New("The server is already started")

ErrServerIsAlreadyStarted represents a error

View Source
var ErrServerIsNotStarted = errors.New("The server is not started")

ErrServerIsNotStarted represents a error

View Source
var ErrTimeout = errors.New("timeout")

ErrTimeout represents a timeout error

View Source
var ErrURIListEmpty = errors.New("uriList must contain at least one uri")

ErrURIListEmpty represents a error

Functions

func CheckAddresses

func CheckAddresses(uriList []string, schemes []string) (scheme string)

CheckAddresses returns the uri scheme if the address is valid.

func CoarseTimeNow

func CoarseTimeNow() time.Time

func DefaultFixArguments

func DefaultFixArguments(args []reflect.Value, context ServiceContext)

DefaultFixArguments is the default FixArguments function

func FireErrorEvent

func FireErrorEvent(event ServiceEvent, e error, context Context) (err error)

FireErrorEvent fires the OnSendError

func RegisterClientFactory

func RegisterClientFactory(scheme string, newClient func(...string) Client)

RegisterClientFactory registers the default client factory

Types

type BaseClient

type BaseClient struct {
	SendAndReceive func([]byte, *ClientContext) ([]byte, error)
	UserData       map[string]interface{}
	// contains filtered or unexported fields
}

BaseClient is hprose base client

func (*BaseClient) AddAfterFilterHandler

func (client *BaseClient) AddAfterFilterHandler(handler ...FilterHandler) Client

AddAfterFilterHandler add the filter handler after filters

func (*BaseClient) AddBeforeFilterHandler

func (client *BaseClient) AddBeforeFilterHandler(handler ...FilterHandler) Client

AddBeforeFilterHandler add the filter handler before filters

func (*BaseClient) AddFilter

func (client *BaseClient) AddFilter(filter ...Filter) Client

AddFilter add the filter to this Service

func (*BaseClient) AddInvokeHandler

func (client *BaseClient) AddInvokeHandler(handler ...InvokeHandler) Client

AddInvokeHandler add the invoke handler to this Service

func (*BaseClient) AutoID

func (client *BaseClient) AutoID() (string, error)

AutoID returns the auto id of this hprose client. If the id is not initialized, it be initialized and returned.

func (*BaseClient) Close

func (client *BaseClient) Close()

Close the client

func (*BaseClient) Failround

func (client *BaseClient) Failround() int

Failround return the fail round

func (*BaseClient) Filter

func (fm *BaseClient) Filter() Filter

Filter return the first filter

func (*BaseClient) FilterByIndex

func (fm *BaseClient) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*BaseClient) GetClientContext

func (client *BaseClient) GetClientContext(
	settings *InvokeSettings) (context *ClientContext)

GetClientContext return a ClientContext

func (*BaseClient) Go

func (client *BaseClient) Go(
	name string,
	args []reflect.Value,
	settings *InvokeSettings,
	callback Callback)

Go invoke the remote method asynchronous

func (*BaseClient) ID

func (client *BaseClient) ID() string

ID returns the auto id of this hprose client. If the id is not initialized, return empty string.

func (*BaseClient) InitBaseClient

func (client *BaseClient) InitBaseClient()

InitBaseClient initializes BaseClient

func (*BaseClient) Invoke

func (client *BaseClient) Invoke(
	name string,
	args []reflect.Value,
	settings *InvokeSettings) (results []reflect.Value, err error)

Invoke the remote method synchronous

func (*BaseClient) IsSubscribed

func (tm *BaseClient) IsSubscribed(topic string) bool

IsSubscribed the topic

func (*BaseClient) NumFilter

func (fm *BaseClient) NumFilter() int

NumFilter return the filter count

func (*BaseClient) RemoveFilter

func (client *BaseClient) RemoveFilter(filter ...Filter) Client

RemoveFilter remove the filter from this Service

func (*BaseClient) RemoveFilterByIndex

func (client *BaseClient) RemoveFilterByIndex(index int) Client

RemoveFilterByIndex remove the filter by the index

func (*BaseClient) Retry

func (client *BaseClient) Retry() int

Retry returns the max retry count

func (*BaseClient) SetEvent

func (client *BaseClient) SetEvent(event ClientEvent)

SetEvent set the client event

func (*BaseClient) SetFilter

func (client *BaseClient) SetFilter(filter ...Filter) Client

SetFilter will replace the current filter settings

func (*BaseClient) SetRetry

func (client *BaseClient) SetRetry(value int)

SetRetry set the max retry count

func (*BaseClient) SetTLSClientConfig

func (client *BaseClient) SetTLSClientConfig(config *tls.Config)

SetTLSClientConfig set the tls config of hprose client

func (*BaseClient) SetTimeout

func (client *BaseClient) SetTimeout(value time.Duration)

SetTimeout set the client timeout setting

func (*BaseClient) SetURI

func (client *BaseClient) SetURI(uri string)

SetURI set the current hprose service address.

If you want to set more than one service address, please don't use this method, use SetURIList instead.

func (*BaseClient) SetURIList

func (client *BaseClient) SetURIList(uriList []string)

SetURIList set a list of server addresses

func (*BaseClient) SetUserData

func (client *BaseClient) SetUserData(
	userdata map[string]interface{}) Client

SetUserData for client

func (*BaseClient) Subscribe

func (client *BaseClient) Subscribe(
	name string, id string,
	settings *InvokeSettings, callback interface{}) (err error)

Subscribe a push topic

func (*BaseClient) SubscribedList

func (tm *BaseClient) SubscribedList() []string

SubscribedList returns the subscribed topic list

func (*BaseClient) TLSClientConfig

func (client *BaseClient) TLSClientConfig() *tls.Config

TLSClientConfig returns the tls config of hprose client

func (*BaseClient) Timeout

func (client *BaseClient) Timeout() time.Duration

Timeout returns the client timeout setting

func (*BaseClient) URI

func (client *BaseClient) URI() string

URI returns the current hprose service address.

func (*BaseClient) URIList

func (client *BaseClient) URIList() []string

URIList returns all of the hprose service addresses

func (*BaseClient) URL

func (client *BaseClient) URL() *url.URL

URL returns the current hprose service address.

func (*BaseClient) Unsubscribe

func (client *BaseClient) Unsubscribe(name string, id ...string)

Unsubscribe a push topic

func (*BaseClient) Use

func (hm *BaseClient) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

func (*BaseClient) UseService

func (client *BaseClient) UseService(
	remoteService interface{}, namespace ...string)

UseService build a remote service proxy object with namespace

type BaseContext

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

BaseContext is the base context

func (*BaseContext) Get

func (context *BaseContext) Get(key string) interface{}

Get value from hprose context

func (*BaseContext) GetBool

func (context *BaseContext) GetBool(
	key string, defaultValue ...bool) bool

GetBool from hprose context

func (*BaseContext) GetFloat

func (context *BaseContext) GetFloat(
	key string, defaultValue ...float64) float64

GetFloat from hprose context

func (*BaseContext) GetInt

func (context *BaseContext) GetInt(
	key string, defaultValue ...int) int

GetInt from hprose context

func (*BaseContext) GetInt64

func (context *BaseContext) GetInt64(
	key string, defaultValue ...int64) int64

GetInt64 from hprose context

func (*BaseContext) GetInterface

func (context *BaseContext) GetInterface(
	key string, defaultValue ...interface{}) interface{}

GetInterface from hprose context

func (*BaseContext) GetString

func (context *BaseContext) GetString(
	key string, defaultValue ...string) string

GetString from hprose context

func (*BaseContext) GetUInt

func (context *BaseContext) GetUInt(
	key string, defaultValue ...uint) uint

GetUInt from hprose context

func (*BaseContext) GetUInt64

func (context *BaseContext) GetUInt64(
	key string, defaultValue ...uint64) uint64

GetUInt64 from hprose context

func (*BaseContext) InitBaseContext

func (context *BaseContext) InitBaseContext()

InitBaseContext initializes BaseContext

func (*BaseContext) Set

func (context *BaseContext) Set(key string, value interface{})

Set is an alias of SetInterface

func (*BaseContext) SetBool

func (context *BaseContext) SetBool(key string, value bool)

SetBool to hprose context

func (*BaseContext) SetFloat

func (context *BaseContext) SetFloat(key string, value float64)

SetFloat to hprose context

func (*BaseContext) SetInt

func (context *BaseContext) SetInt(key string, value int)

SetInt to hprose context

func (*BaseContext) SetInt64

func (context *BaseContext) SetInt64(key string, value int64)

SetInt64 to hprose context

func (*BaseContext) SetInterface

func (context *BaseContext) SetInterface(key string, value interface{})

SetInterface to hprose context

func (*BaseContext) SetString

func (context *BaseContext) SetString(key string, value string)

SetString to hprose context

func (*BaseContext) SetUInt

func (context *BaseContext) SetUInt(key string, value uint)

SetUInt to hprose context

func (*BaseContext) SetUInt64

func (context *BaseContext) SetUInt64(key string, value uint64)

SetUInt64 to hprose context

func (*BaseContext) UserData

func (context *BaseContext) UserData() map[string]interface{}

UserData return the user data

type BaseHTTPService

type BaseHTTPService struct {
	BaseService
	P3P                       bool
	GET                       bool
	CrossDomain               bool
	AccessControlAllowOrigins map[string]bool
	LastModified              string
	Etag                      string
	// contains filtered or unexported fields
}

BaseHTTPService is the hprose base http service

func (*BaseHTTPService) AddAccessControlAllowOrigin

func (service *BaseHTTPService) AddAccessControlAllowOrigin(origins ...string)

AddAccessControlAllowOrigin add access control allow origin

func (*BaseHTTPService) ClientAccessPolicyXMLContent

func (service *BaseHTTPService) ClientAccessPolicyXMLContent() []byte

ClientAccessPolicyXMLContent return the client access policy xml content

func (*BaseHTTPService) ClientAccessPolicyXMLFile

func (service *BaseHTTPService) ClientAccessPolicyXMLFile() string

ClientAccessPolicyXMLFile return the client access policy xml file

func (*BaseHTTPService) CrossDomainXMLContent

func (service *BaseHTTPService) CrossDomainXMLContent() []byte

CrossDomainXMLContent return the cross domain xml content

func (*BaseHTTPService) CrossDomainXMLFile

func (service *BaseHTTPService) CrossDomainXMLFile() string

CrossDomainXMLFile return the cross domain xml file

func (*BaseHTTPService) Filter

func (fm *BaseHTTPService) Filter() Filter

Filter return the first filter

func (*BaseHTTPService) FilterByIndex

func (fm *BaseHTTPService) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*BaseHTTPService) InitBaseHTTPService

func (service *BaseHTTPService) InitBaseHTTPService()

InitBaseHTTPService initializes BaseHTTPService

func (*BaseHTTPService) NumFilter

func (fm *BaseHTTPService) NumFilter() int

NumFilter return the filter count

func (*BaseHTTPService) RemoveAccessControlAllowOrigin

func (service *BaseHTTPService) RemoveAccessControlAllowOrigin(origins ...string)

RemoveAccessControlAllowOrigin remove access control allow origin

func (*BaseHTTPService) SetClientAccessPolicyXMLContent

func (service *BaseHTTPService) SetClientAccessPolicyXMLContent(content []byte)

SetClientAccessPolicyXMLContent set the client access policy xml content

func (*BaseHTTPService) SetClientAccessPolicyXMLFile

func (service *BaseHTTPService) SetClientAccessPolicyXMLFile(filename string)

SetClientAccessPolicyXMLFile set the client access policy xml file

func (*BaseHTTPService) SetCrossDomainXMLContent

func (service *BaseHTTPService) SetCrossDomainXMLContent(content []byte)

SetCrossDomainXMLContent set the cross domain xml content

func (*BaseHTTPService) SetCrossDomainXMLFile

func (service *BaseHTTPService) SetCrossDomainXMLFile(filename string)

SetCrossDomainXMLFile set the cross domain xml file

func (*BaseHTTPService) Use

func (hm *BaseHTTPService) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type BaseService

type BaseService struct {
	FixArguments func(args []reflect.Value, context ServiceContext)
	Event        ServiceEvent
	Debug        bool
	Timeout      time.Duration
	Heartbeat    time.Duration
	ErrorDelay   time.Duration
	UserData     map[string]interface{}
	// contains filtered or unexported fields
}

BaseService is the hprose base service

func (*BaseService) AddAfterFilterHandler

func (service *BaseService) AddAfterFilterHandler(handler ...FilterHandler) Service

AddAfterFilterHandler add the filter handler after filters

func (*BaseService) AddAllMethods

func (service *BaseService) AddAllMethods(obj interface{}, option ...Options) Service

AddAllMethods will publish all methods and non-nil function fields on the obj self and on its anonymous or non-anonymous struct fields (or pointer to pointer ... to pointer struct fields). This is a recursive operation. So it's a pit, if you do not know what you are doing, do not step on.

func (*BaseService) AddBeforeFilterHandler

func (service *BaseService) AddBeforeFilterHandler(handler ...FilterHandler) Service

AddBeforeFilterHandler add the filter handler before filters

func (*BaseService) AddFilter

func (service *BaseService) AddFilter(filter ...Filter) Service

AddFilter add the filter to this Service

func (*BaseService) AddFunction

func (service *BaseService) AddFunction(name string, function interface{}, option ...Options) Service

AddFunction publish a func or bound method name is the method name function is a func or bound method options includes Mode, Simple, Oneway and NameSpace

func (*BaseService) AddFunctions

func (service *BaseService) AddFunctions(names []string, functions []interface{}, option ...Options) Service

AddFunctions is used for batch publishing service method

func (*BaseService) AddInstanceMethods

func (service *BaseService) AddInstanceMethods(obj interface{}, option ...Options) Service

AddInstanceMethods is used for publishing all the public methods and func fields with options.

func (*BaseService) AddInvokeHandler

func (service *BaseService) AddInvokeHandler(handler ...InvokeHandler) Service

AddInvokeHandler add the invoke handler to this Service

func (*BaseService) AddMethod

func (service *BaseService) AddMethod(name string, obj interface{}, alias string, option ...Options) Service

AddMethod is used for publishing a method on the obj with an alias

func (*BaseService) AddMethods

func (service *BaseService) AddMethods(names []string, obj interface{}, aliases []string, option ...Options) Service

AddMethods is used for batch publishing methods on the obj with aliases

func (*BaseService) AddMissingMethod

func (service *BaseService) AddMissingMethod(method MissingMethod, option ...Options) Service

AddMissingMethod is used for publishing a method, all methods not explicitly published will be redirected to this method.

func (*BaseService) AddNetRPCMethods

func (service *BaseService) AddNetRPCMethods(rcvr interface{}, option ...Options) Service

AddNetRPCMethods is used for publishing methods defined for net/rpc.

func (*BaseService) Broadcast

func (service *BaseService) Broadcast(
	topic string, result interface{}, callback func([]string))

Broadcast push result to all clients

func (*BaseService) DoFunctionList

func (service *BaseService) DoFunctionList(context ServiceContext) []byte

DoFunctionList returns the function list

func (*BaseService) EndError

func (service *BaseService) EndError(err error, context Context) []byte

EndError return the error response with TagEnd

func (*BaseService) Exist

func (service *BaseService) Exist(topic string, id string) bool

Exist returns true if the client id exist.

func (*BaseService) Filter

func (fm *BaseService) Filter() Filter

Filter return the first filter

func (*BaseService) FilterByIndex

func (fm *BaseService) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*BaseService) Handle

func (service *BaseService) Handle(request []byte, context Context) []byte

Handle the hprose request and return the hprose response

func (*BaseService) IDList

func (service *BaseService) IDList(topic string) []string

IDList returns the push client id list

func (*BaseService) InitBaseService

func (service *BaseService) InitBaseService()

InitBaseService initializes BaseService

func (*BaseService) Multicast

func (service *BaseService) Multicast(
	topic string, ids []string, result interface{}, callback func([]string))

Multicast result to the specified clients

func (*BaseService) NumFilter

func (fm *BaseService) NumFilter() int

NumFilter return the filter count

func (*BaseService) Publish

func (service *BaseService) Publish(
	topic string,
	timeout time.Duration,
	heartbeat time.Duration) Service

Publish the hprose push topic

func (*BaseService) Push

func (service *BaseService) Push(topic string, result interface{}, id ...string)

Push result to clients

func (*BaseService) Remove

func (service *BaseService) Remove(name string) Service

Remove the published func or method by name

func (*BaseService) RemoveFilter

func (service *BaseService) RemoveFilter(filter ...Filter) Service

RemoveFilter remove the filter from this Service

func (*BaseService) RemoveFilterByIndex

func (service *BaseService) RemoveFilterByIndex(index int) Service

RemoveFilterByIndex remove the filter by the index

func (*BaseService) SetFilter

func (service *BaseService) SetFilter(filter ...Filter) Service

SetFilter will replace the current filter settings

func (*BaseService) SetUserData

func (service *BaseService) SetUserData(
	userdata map[string]interface{}) Service

SetUserData for service

func (*BaseService) Unicast

func (service *BaseService) Unicast(
	topic string, id string, result interface{}, callback func(bool))

Unicast result to then specified client

func (*BaseService) Use

func (hm *BaseService) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type BaseServiceContext

type BaseServiceContext struct {
	BaseContext
	// contains filtered or unexported fields
}

BaseServiceContext is the base service context

func (*BaseServiceContext) ByRef

func (context *BaseServiceContext) ByRef() bool

ByRef returns whether the current invoking is parameter passing by reference.

func (*BaseServiceContext) Clients

func (context *BaseServiceContext) Clients() Clients

Clients returns the Clients interface

func (*BaseServiceContext) InitServiceContext

func (context *BaseServiceContext) InitServiceContext(service Service)

InitServiceContext initializes BaseServiceContext

func (*BaseServiceContext) IsMissingMethod

func (context *BaseServiceContext) IsMissingMethod() bool

IsMissingMethod returns whether the current invoking is missing method

func (*BaseServiceContext) Method

func (context *BaseServiceContext) Method() *Method

Method returns the method of current invoking

func (*BaseServiceContext) Service

func (context *BaseServiceContext) Service() Service

Service returns the Service interface

type Callback

type Callback func([]reflect.Value, error)

Callback is the callback function type of Client.Go

type Client

type Client interface {
	URL() *url.URL
	URI() string
	SetURI(uri string)
	URIList() []string
	SetURIList(uriList []string)
	TLSClientConfig() *tls.Config
	SetTLSClientConfig(config *tls.Config)
	Retry() int
	SetRetry(value int)
	Timeout() time.Duration
	SetTimeout(value time.Duration)
	Failround() int
	SetEvent(ClientEvent)
	Filter() Filter
	FilterByIndex(index int) Filter
	SetFilter(filter ...Filter) Client
	AddFilter(filter ...Filter) Client
	RemoveFilterByIndex(index int) Client
	RemoveFilter(filter ...Filter) Client
	AddInvokeHandler(handler ...InvokeHandler) Client
	AddBeforeFilterHandler(handler ...FilterHandler) Client
	AddAfterFilterHandler(handler ...FilterHandler) Client
	SetUserData(userdata map[string]interface{}) Client
	UseService(remoteService interface{}, namespace ...string)
	Invoke(string, []reflect.Value, *InvokeSettings) ([]reflect.Value, error)
	Go(string, []reflect.Value, *InvokeSettings, Callback)
	Close()
	AutoID() (string, error)
	ID() string
	Subscribe(name string, id string, settings *InvokeSettings, callback interface{}) (err error)
	Unsubscribe(name string, id ...string)
	IsSubscribed(name string) bool
	SubscribedList() []string
}

Client is hprose client

func NewClient

func NewClient(uri ...string) Client

NewClient is the constructor of Client

type ClientContext

type ClientContext struct {
	BaseContext
	InvokeSettings
	Retried int
	Client  Client
}

ClientContext is the hprose client context

type ClientEvent

type ClientEvent interface{}

ClientEvent is the client event

type Clients

type Clients interface {
	IDList(topic string) []string
	Exist(topic string, id string) bool
	Push(topic string, result interface{}, id ...string)
	Broadcast(topic string, result interface{}, callback func([]string))
	Multicast(topic string, ids []string, result interface{}, callback func([]string))
	Unicast(topic string, id string, result interface{}, callback func(bool))
}

Clients interface for server push

type Context

type Context interface {
	UserData() map[string]interface{}
	GetInt(key string, defaultValue ...int) int
	GetUInt(key string, defaultValue ...uint) uint
	GetInt64(key string, defaultValue ...int64) int64
	GetUInt64(key string, defaultValue ...uint64) uint64
	GetFloat(key string, defaultValue ...float64) float64
	GetBool(key string, defaultValue ...bool) bool
	GetString(key string, defaultValue ...string) string
	GetInterface(key string, defaultValue ...interface{}) interface{}
	Get(key string) interface{}
	SetInt(key string, value int)
	SetUInt(key string, value uint)
	SetInt64(key string, value int64)
	SetUInt64(key string, value uint64)
	SetFloat(key string, value float64)
	SetBool(key string, value bool)
	SetString(key string, value string)
	SetInterface(key string, value interface{})
	Set(key string, value interface{})
}

Context is the hprose context

type Filter

type Filter interface {
	InputFilter(data []byte, context Context) []byte
	OutputFilter(data []byte, context Context) []byte
}

Filter is hprose filter

type FilterHandler

type FilterHandler func(
	request []byte,
	context Context,
	next NextFilterHandler) (response []byte, err error)

FilterHandler is the filter handler function

type HTTPClient

type HTTPClient struct {
	BaseClient
	http.Transport
	Header http.Header
	// contains filtered or unexported fields
}

HTTPClient is hprose http client

func NewHTTPClient

func NewHTTPClient(uri ...string) (client *HTTPClient)

NewHTTPClient is the constructor of HTTPClient

func (*HTTPClient) Compression

func (client *HTTPClient) Compression() bool

Compression returns the compression status of hprose client

func (*HTTPClient) Filter

func (fm *HTTPClient) Filter() Filter

Filter return the first filter

func (*HTTPClient) FilterByIndex

func (fm *HTTPClient) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*HTTPClient) IsSubscribed

func (tm *HTTPClient) IsSubscribed(topic string) bool

IsSubscribed the topic

func (*HTTPClient) KeepAlive

func (client *HTTPClient) KeepAlive() bool

KeepAlive returns the keepalive status of hprose client

func (*HTTPClient) MaxConcurrentRequests

func (client *HTTPClient) MaxConcurrentRequests() int

MaxConcurrentRequests returns max concurrent request count

func (*HTTPClient) NumFilter

func (fm *HTTPClient) NumFilter() int

NumFilter return the filter count

func (*HTTPClient) SetCompression

func (client *HTTPClient) SetCompression(enable bool)

SetCompression sets the compression status of hprose client

func (*HTTPClient) SetKeepAlive

func (client *HTTPClient) SetKeepAlive(enable bool)

SetKeepAlive sets the keepalive status of hprose client

func (*HTTPClient) SetMaxConcurrentRequests

func (client *HTTPClient) SetMaxConcurrentRequests(value int)

SetMaxConcurrentRequests sets max concurrent request count

func (*HTTPClient) SetTLSClientConfig

func (client *HTTPClient) SetTLSClientConfig(config *tls.Config)

SetTLSClientConfig sets the tls.Config

func (*HTTPClient) SetURIList

func (client *HTTPClient) SetURIList(uriList []string)

SetURIList sets a list of server addresses

func (*HTTPClient) SubscribedList

func (tm *HTTPClient) SubscribedList() []string

SubscribedList returns the subscribed topic list

func (*HTTPClient) TLSClientConfig

func (client *HTTPClient) TLSClientConfig() *tls.Config

TLSClientConfig returns the tls.Config in hprose client

func (*HTTPClient) Use

func (hm *HTTPClient) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type HTTPContext

type HTTPContext struct {
	BaseServiceContext
	Response http.ResponseWriter
	Request  *http.Request
}

HTTPContext is the hprose http context

func (*HTTPContext) InitHTTPContext

func (context *HTTPContext) InitHTTPContext(
	service Service,
	response http.ResponseWriter,
	request *http.Request)

InitHTTPContext initializes HTTPContext

type HTTPService

type HTTPService struct {
	BaseHTTPService
	// contains filtered or unexported fields
}

HTTPService is the hprose http service

func NewHTTPService

func NewHTTPService() (service *HTTPService)

NewHTTPService is the constructor of HTTPService

func (*HTTPService) Filter

func (fm *HTTPService) Filter() Filter

Filter return the first filter

func (*HTTPService) FilterByIndex

func (fm *HTTPService) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*HTTPService) InitHTTPService

func (service *HTTPService) InitHTTPService()

InitHTTPService initializes HTTPService

func (*HTTPService) NumFilter

func (fm *HTTPService) NumFilter() int

NumFilter return the filter count

func (*HTTPService) ServeHTTP

func (service *HTTPService) ServeHTTP(
	response http.ResponseWriter, request *http.Request)

ServeHTTP is the hprose http handler method

func (*HTTPService) Use

func (hm *HTTPService) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type InvokeHandler

type InvokeHandler func(
	name string,
	args []reflect.Value,
	context Context,
	next NextInvokeHandler) (results []reflect.Value, err error)

InvokeHandler is the invoke handler function

type InvokeSettings

type InvokeSettings struct {
	ByRef          bool
	Simple         bool
	Idempotent     bool
	Failswitch     bool
	Oneway         bool
	JSONCompatible bool
	Retry          int
	Mode           ResultMode
	Timeout        time.Duration
	ResultTypes    []reflect.Type
	// contains filtered or unexported fields
}

InvokeSettings is the invoke settings of hprose client

func (*InvokeSettings) SetUserData

func (settings *InvokeSettings) SetUserData(data map[string]interface{})

SetUserData on InvokeSettings

type Limiter

type Limiter struct {
	MaxConcurrentRequests int

	sync.Cond
	// contains filtered or unexported fields
}

Limiter is a request limiter

func (*Limiter) InitLimiter

func (limiter *Limiter) InitLimiter()

InitLimiter initializes Limiter

func (*Limiter) Limit

func (limiter *Limiter) Limit()

Limit the request

func (*Limiter) Reset

func (limiter *Limiter) Reset()

Reset the Limiter

func (*Limiter) Unlimit

func (limiter *Limiter) Unlimit()

Unlimit the request

type Method

type Method struct {
	Function reflect.Value
	Options
}

Method is the published service method

type MissingMethod

type MissingMethod func(name string, args []reflect.Value, context Context) (result []reflect.Value, err error)

MissingMethod is missing method

type NextFilterHandler

type NextFilterHandler func(
	request []byte,
	context Context) (response []byte, err error)

NextFilterHandler is the next filter handler function

type NextInvokeHandler

type NextInvokeHandler func(
	name string,
	args []reflect.Value,
	context Context) (results []reflect.Value, err error)

NextInvokeHandler is the next invoke handler function

type Options

type Options struct {
	Mode           ResultMode
	Simple         bool
	Oneway         bool
	NameSpace      string
	JSONCompatible bool
}

Options is the options of the published service method

type PanicError

type PanicError struct {
	Panic interface{}
	Stack []byte
}

PanicError represents a panic error

func NewPanicError

func NewPanicError(v interface{}) *PanicError

NewPanicError return a panic error

func (*PanicError) Error

func (pe *PanicError) Error() string

Error implements the PanicError Error method.

type ResultMode

type ResultMode int

ResultMode is result mode

func (ResultMode) String

func (mode ResultMode) String() string

type Server

type Server interface {
	Service
	URI() string
	Handle() (err error)
	Close()
	Start() (err error)
	Restart()
	Stop()
}

Server interface

type Service

type Service interface {
	AddFunction(name string, function interface{}, option ...Options) Service
	AddFunctions(names []string, functions []interface{}, option ...Options) Service
	AddMethod(name string, obj interface{}, alias string, option ...Options) Service
	AddMethods(names []string, obj interface{}, aliases []string, option ...Options) Service
	AddInstanceMethods(obj interface{}, option ...Options) Service
	AddAllMethods(obj interface{}, option ...Options) Service
	AddMissingMethod(method MissingMethod, option ...Options) Service
	AddNetRPCMethods(rcvr interface{}, option ...Options) Service
	Remove(name string) Service
	Filter() Filter
	FilterByIndex(index int) Filter
	SetFilter(filter ...Filter) Service
	AddFilter(filter ...Filter) Service
	RemoveFilterByIndex(index int) Service
	RemoveFilter(filter ...Filter) Service
	AddInvokeHandler(handler ...InvokeHandler) Service
	AddBeforeFilterHandler(handler ...FilterHandler) Service
	AddAfterFilterHandler(handler ...FilterHandler) Service
	SetUserData(userdata map[string]interface{}) Service
	Publish(topic string, timeout time.Duration, heartbeat time.Duration) Service
	Clients
}

Service interface

type ServiceContext

type ServiceContext interface {
	Context
	Service() Service
	Clients() Clients
	Method() *Method
	IsMissingMethod() bool
	ByRef() bool
	// contains filtered or unexported methods
}

ServiceContext is the hprose service context

type ServiceEvent

type ServiceEvent interface{}

ServiceEvent is the service event

type SocketClient

type SocketClient struct {
	BaseClient

	ReadBuffer  int
	WriteBuffer int
	TLSConfig   *tls.Config
	// contains filtered or unexported fields
}

SocketClient is base struct for TCPClient and UnixClient

func (*SocketClient) Close

func (client *SocketClient) Close()

Close the client

func (*SocketClient) Filter

func (fm *SocketClient) Filter() Filter

Filter return the first filter

func (*SocketClient) FilterByIndex

func (fm *SocketClient) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*SocketClient) IsSubscribed

func (tm *SocketClient) IsSubscribed(topic string) bool

IsSubscribed the topic

func (*SocketClient) NumFilter

func (fm *SocketClient) NumFilter() int

NumFilter return the filter count

func (*SocketClient) SetTLSClientConfig

func (client *SocketClient) SetTLSClientConfig(config *tls.Config)

SetTLSClientConfig sets the tls.Config

func (*SocketClient) SubscribedList

func (tm *SocketClient) SubscribedList() []string

SubscribedList returns the subscribed topic list

func (*SocketClient) TLSClientConfig

func (client *SocketClient) TLSClientConfig() *tls.Config

TLSClientConfig returns the tls.Config in hprose client

func (*SocketClient) Use

func (hm *SocketClient) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type SocketContext

type SocketContext struct {
	BaseServiceContext
	net.Conn
}

SocketContext is the hprose socket context for service

type SocketService

type SocketService struct {
	BaseService
	TLSConfig *tls.Config
	// contains filtered or unexported fields
}

SocketService is the hprose socket service

func (*SocketService) Filter

func (fm *SocketService) Filter() Filter

Filter return the first filter

func (*SocketService) FilterByIndex

func (fm *SocketService) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*SocketService) NumFilter

func (fm *SocketService) NumFilter() int

NumFilter return the filter count

func (*SocketService) Use

func (hm *SocketService) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type TCPClient

type TCPClient struct {
	SocketClient
	Linger          int
	NoDelay         bool
	KeepAlive       bool
	KeepAlivePeriod time.Duration
}

TCPClient is hprose tcp client

func NewTCPClient

func NewTCPClient(uri ...string) (client *TCPClient)

NewTCPClient is the constructor of TCPClient

func (*TCPClient) Filter

func (fm *TCPClient) Filter() Filter

Filter return the first filter

func (*TCPClient) FilterByIndex

func (fm *TCPClient) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*TCPClient) IsSubscribed

func (tm *TCPClient) IsSubscribed(topic string) bool

IsSubscribed the topic

func (*TCPClient) NumFilter

func (fm *TCPClient) NumFilter() int

NumFilter return the filter count

func (*TCPClient) SetURIList

func (client *TCPClient) SetURIList(uriList []string)

SetURIList set a list of server addresses

func (*TCPClient) SubscribedList

func (tm *TCPClient) SubscribedList() []string

SubscribedList returns the subscribed topic list

func (*TCPClient) Use

func (hm *TCPClient) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type TCPServer

type TCPServer struct {
	TCPService
	// contains filtered or unexported fields
}

TCPServer is a hprose tcp server

func NewTCPServer

func NewTCPServer(uri string) (server *TCPServer)

NewTCPServer is the constructor for TCPServer

func (*TCPServer) Close

func (server *TCPServer) Close()

Close the hprose tcp server

func (*TCPServer) Filter

func (fm *TCPServer) Filter() Filter

Filter return the first filter

func (*TCPServer) FilterByIndex

func (fm *TCPServer) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*TCPServer) Handle

func (server *TCPServer) Handle() (err error)

Handle the hprose tcp server

func (*TCPServer) NumFilter

func (fm *TCPServer) NumFilter() int

NumFilter return the filter count

func (*TCPServer) Restart

func (starter *TCPServer) Restart()

Restart the hprose server

func (*TCPServer) Start

func (starter *TCPServer) Start() (err error)

Start the hprose server

func (*TCPServer) Stop

func (starter *TCPServer) Stop()

Stop the hprose server

func (*TCPServer) URI

func (server *TCPServer) URI() string

URI return the real address of this server

func (*TCPServer) Use

func (hm *TCPServer) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type TCPService

type TCPService struct {
	SocketService
	Linger          int
	NoDelay         bool
	KeepAlive       bool
	KeepAlivePeriod time.Duration
}

TCPService is the hprose tcp service

func NewTCPService

func NewTCPService() (service *TCPService)

NewTCPService is the constructor of TCPService

func (*TCPService) Filter

func (fm *TCPService) Filter() Filter

Filter return the first filter

func (*TCPService) FilterByIndex

func (fm *TCPService) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*TCPService) NumFilter

func (fm *TCPService) NumFilter() int

NumFilter return the filter count

func (*TCPService) Serve

func (service *TCPService) Serve(listener net.Listener)

Serve runs on the Listener. Serve blocks, serving the listener until the server is stop. The caller typically invokes Serve in a go statement.

func (*TCPService) ServeConn

func (service *TCPService) ServeConn(conn net.Conn)

ServeConn runs on a single net connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

func (*TCPService) ServeTCP

func (service *TCPService) ServeTCP(listener *net.TCPListener)

ServeTCP runs on the TCPListener. ServeTCP blocks, serving the listener until the server is stop. The caller typically invokes ServeTCP in a go statement.

func (*TCPService) ServeTCPConn

func (service *TCPService) ServeTCPConn(conn *net.TCPConn)

ServeTCPConn runs on a single tcp connection. ServeTCPConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeTCPConn in a go statement.

func (*TCPService) Use

func (hm *TCPService) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type UnixClient

type UnixClient struct {
	SocketClient
}

UnixClient is hprose unix client

func NewUnixClient

func NewUnixClient(uri ...string) (client *UnixClient)

NewUnixClient is the constructor of UnixClient

func (*UnixClient) Filter

func (fm *UnixClient) Filter() Filter

Filter return the first filter

func (*UnixClient) FilterByIndex

func (fm *UnixClient) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*UnixClient) IsSubscribed

func (tm *UnixClient) IsSubscribed(topic string) bool

IsSubscribed the topic

func (*UnixClient) NumFilter

func (fm *UnixClient) NumFilter() int

NumFilter return the filter count

func (*UnixClient) SetURIList

func (client *UnixClient) SetURIList(uriList []string)

SetURIList set a list of server addresses

func (*UnixClient) SubscribedList

func (tm *UnixClient) SubscribedList() []string

SubscribedList returns the subscribed topic list

func (*UnixClient) Use

func (hm *UnixClient) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type UnixServer

type UnixServer struct {
	UnixService
	// contains filtered or unexported fields
}

UnixServer is a hprose unix server

func NewUnixServer

func NewUnixServer(uri string) (server *UnixServer)

NewUnixServer is the constructor for UnixServer

func (*UnixServer) Close

func (server *UnixServer) Close()

Close the hprose unix server

func (*UnixServer) Filter

func (fm *UnixServer) Filter() Filter

Filter return the first filter

func (*UnixServer) FilterByIndex

func (fm *UnixServer) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*UnixServer) Handle

func (server *UnixServer) Handle() (err error)

Handle the hprose unix server

func (*UnixServer) NumFilter

func (fm *UnixServer) NumFilter() int

NumFilter return the filter count

func (*UnixServer) Restart

func (starter *UnixServer) Restart()

Restart the hprose server

func (*UnixServer) Start

func (starter *UnixServer) Start() (err error)

Start the hprose server

func (*UnixServer) Stop

func (starter *UnixServer) Stop()

Stop the hprose server

func (*UnixServer) URI

func (server *UnixServer) URI() string

URI return the real address of this server

func (*UnixServer) Use

func (hm *UnixServer) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type UnixService

type UnixService struct {
	SocketService
}

UnixService is the hprose unix service

func NewUnixService

func NewUnixService() (service *UnixService)

NewUnixService is the constructor of UnixService

func (*UnixService) Filter

func (fm *UnixService) Filter() Filter

Filter return the first filter

func (*UnixService) FilterByIndex

func (fm *UnixService) FilterByIndex(index int) Filter

FilterByIndex return the filter by index

func (*UnixService) NumFilter

func (fm *UnixService) NumFilter() int

NumFilter return the filter count

func (*UnixService) Serve

func (service *UnixService) Serve(listener net.Listener)

Serve runs on the Listener. Serve blocks, serving the listener until the server is stop. The caller typically invokes Serve in a go statement.

func (*UnixService) ServeConn

func (service *UnixService) ServeConn(conn net.Conn)

ServeConn runs on a single net connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

func (*UnixService) ServeUnix

func (service *UnixService) ServeUnix(listener *net.UnixListener)

ServeUnix runs on the UnixListener. ServeUnix blocks, serving the listener until the server is stop. The caller typically invokes ServeUnix in a go statement.

func (*UnixService) ServeUnixConn

func (service *UnixService) ServeUnixConn(conn *net.UnixConn)

ServeUnixConn runs on a single tcp connection. ServeUnixConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeUnixConn in a go statement.

func (*UnixService) Use

func (hm *UnixService) Use(handler ...InvokeHandler)

Use is a method alias of AddInvokeHandler

type WorkerPool

type WorkerPool struct {
	MaxWorkersCount int

	MaxIdleWorkerDuration time.Duration
	// contains filtered or unexported fields
}

WorkerPool serves outgoing connections via a pool of workers in FILO order, i.e. the most recently stopped worker will serve the next incoming connection.

Such a scheme keeps CPU caches hot (in theory).

func (*WorkerPool) Go

func (wp *WorkerPool) Go(c func()) bool

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Directories

Path Synopsis
filter

Jump to

Keyboard shortcuts

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