Documentation ¶
Overview ¶
Package hprose client example:
package main import ( "fmt" "hprose" ) type testUser struct { Name string Sex int Birthday time.Time Age int Married bool } type testRemoteObject struct { Hello func(string) string HelloWithError func(string) (string, error) `name:"hello"` AsyncHello func(string) <-chan string `name:"hello"` AsyncHelloWithError func(string) (<-chan string, <-chan error) `name:"hello"` Sum func(...int) int SwapKeyAndValue func(*map[string]string) map[string]string `byref:"true"` SwapInt func(int, int) (int, int) `name:"swap"` SwapFloat func(float64, float64) (float64, float64) `name:"swap"` Swap func(interface{}, interface{}) (interface{}, interface{}) GetUserList func() []testUser } func main() { client := hprose.NewClient("http://www.hprose.com/example/") var ro *RemoteObject client.UseService(&ro) // If an error occurs, it will panic fmt.Println(ro.Hello("World")) // If an error occurs, an error value will be returned if result, err := ro.HelloWithError("World"); err == nil { fmt.Println(result) } else { fmt.Println(err.Error()) } // If an error occurs, it will be ignored result := ro.AsyncHello("World") fmt.Println(<-result) // If an error occurs, an error chan will be returned result, err := ro.AsyncHelloWithError("World") if e := <-err; e == nil { fmt.Println(<-result) } else { fmt.Println(e.Error()) } fmt.Println(ro.Sum(1, 2, 3, 4, 5)) m := make(map[string]string) m["Jan"] = "January" m["Feb"] = "February" m["Mar"] = "March" m["Apr"] = "April" m["May"] = "May" m["Jun"] = "June" m["Jul"] = "July" m["Aug"] = "August" m["Sep"] = "September" m["Oct"] = "October" m["Nov"] = "November" m["Dec"] = "December" fmt.Println(m) mm := ro.SwapKeyAndValue(&m) fmt.Println(m) fmt.Println(mm) fmt.Println(ro.GetUserList()) fmt.Println(ro.SwapInt(1, 2)) fmt.Println(ro.SwapFloat(1.2, 3.4)) fmt.Println(ro.Swap("Hello", "World")) }
Package hprose is a High Performance Remote Object Service Engine.
It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.
Hprose supports many programming languages, for example:
- AAuto Quicker
- ActionScript
- ASP
- C++
- Dart
- Delphi/Free Pascal
- dotNET(C#, Visual Basic...)
- Golang
- Java
- JavaScript
- Node.js
- Objective-C
- Perl
- PHP
- Python
- Ruby
- ...
Through Hprose, You can conveniently and efficiently intercommunicate between those programming languages.
This project is the implementation of Hprose for Golang.
Index ¶
- Constants
- Variables
- func Marshal(v interface{}) ([]byte, error)
- func RegisterClientFactory(scheme string, newClient func(string) Client)
- func Serialize(v interface{}, simple bool) ([]byte, error)
- func Unmarshal(b []byte, p interface{}) error
- func Unserialize(b []byte, p interface{}, simple bool) error
- type ArgsFixer
- type BaseClient
- func (client *BaseClient) AddFilter(filter Filter)
- func (client *BaseClient) GetFilter() Filter
- func (client *BaseClient) Invoke(name string, args []interface{}, options *InvokeOptions, result interface{}) <-chan error
- func (client *BaseClient) RemoveFilter(filter Filter)
- func (client *BaseClient) SetFilter(filter Filter)
- func (client *BaseClient) SetUri(uri string)
- func (client *BaseClient) Uri() string
- func (client *BaseClient) UseService(args ...interface{})
- type BaseContext
- func (context *BaseContext) GetBool(key string) (value bool, ok bool)
- func (context *BaseContext) GetFloat(key string) (value float64, ok bool)
- func (context *BaseContext) GetInt(key string) (value int, ok bool)
- func (context *BaseContext) GetInt64(key string) (value int64, ok bool)
- func (context *BaseContext) GetInterface(key string) (value interface{}, ok bool)
- func (context *BaseContext) GetString(key string) (value string, ok bool)
- func (context *BaseContext) GetUInt(key string) (value uint, ok bool)
- func (context *BaseContext) GetUInt64(key string) (value uint64, ok bool)
- func (context *BaseContext) SetBool(key string, value bool)
- func (context *BaseContext) SetFloat(key string, value float64)
- func (context *BaseContext) SetInt(key string, value int)
- func (context *BaseContext) SetInt64(key string, value int64)
- func (context *BaseContext) SetInterface(key string, value interface{})
- func (context *BaseContext) SetString(key string, value string)
- func (context *BaseContext) SetUInt(key string, value uint)
- func (context *BaseContext) SetUInt64(key string, value uint64)
- func (context *BaseContext) UserData() map[string]interface{}
- type BaseService
- type BufReader
- type BufWriter
- type BytesReader
- type Client
- type ClientContext
- type ConnEntry
- type ConnPool
- type Context
- type Filter
- type HttpClient
- func (client *HttpClient) Close()
- func (client *HttpClient) Compression() bool
- func (client *HttpClient) Header() *http.Header
- func (client *HttpClient) Http() *http.Client
- func (client *HttpClient) KeepAlive() bool
- func (client *HttpClient) MaxIdleConnsPerHost() int
- func (client *HttpClient) SetCompression(enable bool)
- func (client *HttpClient) SetKeepAlive(enable bool)
- func (client *HttpClient) SetMaxIdleConnsPerHost(value int)
- func (client *HttpClient) SetTLSClientConfig(config *tls.Config)
- func (client *HttpClient) SetUri(uri string)
- func (client *HttpClient) TLSClientConfig() *tls.Config
- type HttpContext
- type HttpService
- func (service *HttpService) AddAccessControlAllowOrigin(origin string)
- func (service *HttpService) ClientAccessPolicyXmlContent() []byte
- func (service *HttpService) ClientAccessPolicyXmlFile() string
- func (service *HttpService) CrossDomainXmlContent() []byte
- func (service *HttpService) CrossDomainXmlFile() string
- func (service *HttpService) RemoveAccessControlAllowOrigin(origin string)
- func (service *HttpService) Serve(response http.ResponseWriter, request *http.Request, ...)
- func (service *HttpService) ServeHTTP(response http.ResponseWriter, request *http.Request)
- func (service *HttpService) SetClientAccessPolicyXmlContent(content []byte)
- func (service *HttpService) SetClientAccessPolicyXmlFile(filename string)
- func (service *HttpService) SetCrossDomainXmlContent(content []byte)
- func (service *HttpService) SetCrossDomainXmlFile(filename string)
- type HttpServiceEvent
- type InvokeOptions
- type JSONRPCClientFilter
- type JSONRPCServiceFilter
- type Method
- type Methods
- func (methods *Methods) AddAllMethods(obj interface{}, options ...interface{})
- func (methods *Methods) AddFunction(name string, function interface{}, options ...interface{})
- func (methods *Methods) AddFunctions(names []string, functions []interface{}, options ...interface{})
- func (methods *Methods) AddMethods(obj interface{}, options ...interface{})
- func (methods *Methods) AddMissingMethod(method MissingMethod, options ...interface{})
- type MissingMethod
- type RawReader
- type Reader
- func (r *Reader) CheckTag(expectTag byte) error
- func (r *Reader) CheckTags(expectTags []byte) (tag byte, err error)
- func (r *Reader) ReadArray(a []reflect.Value) error
- func (r *Reader) ReadBigInt() (*big.Int, error)
- func (r *Reader) ReadBigIntWithoutTag() (*big.Int, error)
- func (r *Reader) ReadBool() (bool, error)
- func (r *Reader) ReadBytes() (*[]byte, error)
- func (r *Reader) ReadBytesWithoutTag() (*[]byte, error)
- func (r *Reader) ReadDateTime() (time.Time, error)
- func (r *Reader) ReadDateWithoutTag() (time.Time, error)
- func (r *Reader) ReadFloat32() (float32, error)
- func (r *Reader) ReadFloat32WithoutTag() (float32, error)
- func (r *Reader) ReadFloat64() (float64, error)
- func (r *Reader) ReadFloat64WithoutTag() (float64, error)
- func (r *Reader) ReadInt() (int, error)
- func (r *Reader) ReadInt16() (int16, error)
- func (r *Reader) ReadInt16WithoutTag() (int16, error)
- func (r *Reader) ReadInt32() (int32, error)
- func (r *Reader) ReadInt32WithoutTag() (int32, error)
- func (r *Reader) ReadInt64() (int64, error)
- func (r *Reader) ReadInt64WithoutTag() (int64, error)
- func (r *Reader) ReadInt8() (int8, error)
- func (r *Reader) ReadInt8WithoutTag() (int8, error)
- func (r *Reader) ReadIntWithoutTag() (int, error)
- func (r *Reader) ReadInteger(tag byte) (int, error)
- func (r *Reader) ReadList() (*list.List, error)
- func (r *Reader) ReadListWithoutTag() (*list.List, error)
- func (r *Reader) ReadMap(p interface{}) error
- func (r *Reader) ReadMapWithoutTag(p interface{}) error
- func (r *Reader) ReadObject(p interface{}) error
- func (r *Reader) ReadObjectWithoutTag(p interface{}) error
- func (r *Reader) ReadSlice(p interface{}) error
- func (r *Reader) ReadSliceWithoutTag(p interface{}) error
- func (r *Reader) ReadString() (string, error)
- func (r *Reader) ReadStringWithoutTag() (str string, err error)
- func (r *Reader) ReadTimeWithoutTag() (time.Time, error)
- func (r *Reader) ReadUUID() (*UUID, error)
- func (r *Reader) ReadUUIDWithoutTag() (*UUID, error)
- func (r *Reader) ReadUint() (uint, error)
- func (r *Reader) ReadUint16() (uint16, error)
- func (r *Reader) ReadUint16WithoutTag() (uint16, error)
- func (r *Reader) ReadUint32() (uint32, error)
- func (r *Reader) ReadUint32WithoutTag() (uint32, error)
- func (r *Reader) ReadUint64() (uint64, error)
- func (r *Reader) ReadUint64WithoutTag() (uint64, error)
- func (r *Reader) ReadUint8() (uint8, error)
- func (r *Reader) ReadUint8WithoutTag() (uint8, error)
- func (r *Reader) ReadUintWithoutTag() (uint, error)
- func (r *Reader) ReadUinteger(tag byte) (uint, error)
- func (r *Reader) ReadValue(v reflect.Value) error
- func (r *Reader) Reset()
- func (r *Reader) Unserialize(p interface{}) (err error)
- type ResultMode
- type ServiceEvent
- type StreamClient
- type StreamContext
- type StreamService
- type TcpClient
- func (client *TcpClient) Close()
- func (client *TcpClient) SetConnPool(connPool ConnPool)
- func (client *TcpClient) SetKeepAlive(keepalive bool)
- func (client *TcpClient) SetKeepAlivePeriod(d time.Duration)
- func (client *TcpClient) SetLinger(sec int)
- func (client *TcpClient) SetNoDelay(noDelay bool)
- func (client *TcpClient) SetTLSClientConfig(config *tls.Config)
- func (client *TcpClient) SetTimeout(d time.Duration)
- func (client *TcpClient) SetUri(uri string)
- func (client *TcpClient) TLSClientConfig() *tls.Config
- func (client *TcpClient) Timeout() time.Duration
- type TcpContext
- type TcpServer
- type TcpService
- func (service *TcpService) ServeTCP(conn *net.TCPConn) (err error)
- func (service *TcpService) SetKeepAlive(keepalive bool)
- func (service *TcpService) SetKeepAlivePeriod(d time.Duration)
- func (service *TcpService) SetLinger(sec int)
- func (service *TcpService) SetNoDelay(noDelay bool)
- func (service *TcpService) SetTLSConfig(config *tls.Config)
- type Transporter
- type UUID
- type UnixClient
- func (client *UnixClient) Close()
- func (client *UnixClient) SetConnPool(connPool ConnPool)
- func (client *UnixClient) SetKeepAlive(keepalive bool)
- func (client *UnixClient) SetTLSClientConfig(config *tls.Config)
- func (client *UnixClient) SetTimeout(d time.Duration)
- func (client *UnixClient) SetUri(uri string)
- func (client *UnixClient) TLSClientConfig() *tls.Config
- func (client *UnixClient) Timeout() time.Duration
- type UnixContext
- type UnixServer
- type UnixService
- type WebSocketClient
- func (client *WebSocketClient) Close()
- func (client *WebSocketClient) Header() *http.Header
- func (client *WebSocketClient) MaxConcurrentRequests() int
- func (client *WebSocketClient) SetKeepAlive(enable bool)
- func (client *WebSocketClient) SetMaxConcurrentRequests(value int)
- func (client *WebSocketClient) SetTLSClientConfig(config *tls.Config)
- func (client *WebSocketClient) SetUri(uri string)
- func (client *WebSocketClient) TLSClientConfig() *tls.Config
- type WebSocketContext
- type WebSocketService
- type Writer
- func (w *Writer) Reset()
- func (w *Writer) Serialize(v interface{}) (err error)
- func (w *Writer) WriteArray(v []reflect.Value) (err error)
- func (w *Writer) WriteBigInt(v *big.Int) (err error)
- func (w *Writer) WriteBool(v bool) error
- func (w *Writer) WriteBytes(bytes []byte) (err error)
- func (w *Writer) WriteBytesWithRef(bytes []byte) (err error)
- func (w *Writer) WriteFloat64(v float64) (err error)
- func (w *Writer) WriteInt64(v int64) (err error)
- func (w *Writer) WriteNull() error
- func (w *Writer) WriteString(str string) (err error)
- func (w *Writer) WriteStringWithRef(str string) (err error)
- func (w *Writer) WriteTime(t time.Time) (err error)
- func (w *Writer) WriteUint64(v uint64) (err error)
- func (w *Writer) WriteValue(v reflect.Value) (err error)
Constants ¶
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 )
const ( /* Serialize Tags */ TagInteger byte = 'i' TagLong byte = 'l' TagDouble byte = 'd' TagNull byte = 'n' TagEmpty byte = 'e' TagTrue byte = 't' TagFalse byte = 'f' TagNaN byte = 'N' TagInfinity byte = 'I' TagDate byte = 'D' TagTime byte = 'T' TagUTC byte = 'Z' TagBytes byte = 'b' TagUTF8Char byte = 'u' TagString byte = 's' TagGuid byte = 'g' TagList byte = 'a' TagMap byte = 'm' TagClass byte = 'c' TagObject byte = 'o' TagRef byte = 'r' /* Serialize Marks */ TagPos byte = '+' TagNeg byte = '-' TagSemicolon byte = ';' TagOpenbrace byte = '{' TagClosebrace byte = '}' TagQuote byte = '"' TagPoint byte = '.' /* Protocol Tags */ TagFunctions byte = 'F' TagCall byte = 'C' TagResult byte = 'R' TagArgument byte = 'A' TagError byte = 'E' TagEnd byte = 'z' )
Variables ¶
var ClassManager = initClassManager()
ClassManager used to be register class with alias for hprose serialize/unserialize.
var DisableGlobalCookie = false
DisableGlobalCookie is a flag to disable global cookie
var ErrNil = errors.New("nil")
ErrNil is a error of nil
Functions ¶
func RegisterClientFactory ¶
RegisterClientFactory register client factory
Types ¶
type ArgsFixer ¶
type ArgsFixer interface {
FixArgs(args []reflect.Value, lastParamType reflect.Type, context Context) []reflect.Value
}
ArgsFixer ...
type BaseClient ¶
type BaseClient struct { Transporter Client ByRef bool SimpleMode bool DebugEnabled bool // contains filtered or unexported fields }
BaseClient is the hprose base client
func NewBaseClient ¶
func NewBaseClient(trans Transporter) *BaseClient
NewBaseClient is the constructor of BaseClient
func (*BaseClient) AddFilter ¶
func (client *BaseClient) AddFilter(filter Filter)
AddFilter add a filter
func (*BaseClient) GetFilter ¶
func (client *BaseClient) GetFilter() Filter
GetFilter return the first filter
func (*BaseClient) Invoke ¶
func (client *BaseClient) Invoke(name string, args []interface{}, options *InvokeOptions, result interface{}) <-chan error
Invoke the remote method
func (*BaseClient) RemoveFilter ¶
func (client *BaseClient) RemoveFilter(filter Filter)
RemoveFilter remove a filter
func (*BaseClient) SetFilter ¶
func (client *BaseClient) SetFilter(filter Filter)
SetFilter set the only filter
func (*BaseClient) SetUri ¶
func (client *BaseClient) SetUri(uri string)
SetUri set the uri of hprose client
func (*BaseClient) UseService ¶
func (client *BaseClient) UseService(args ...interface{})
UseService (uri string) UseService (remoteObject interface{}) UseService (uri string, remoteObject interface{})
type BaseContext ¶
type BaseContext struct {
// contains filtered or unexported fields
}
BaseContext is the hprose base context
func NewBaseContext ¶
func NewBaseContext() (context *BaseContext)
NewBaseContext is the constructor of BaseContext
func (*BaseContext) GetBool ¶
func (context *BaseContext) GetBool(key string) (value bool, ok bool)
GetBool from hprose context
func (*BaseContext) GetFloat ¶
func (context *BaseContext) GetFloat(key string) (value float64, ok bool)
GetFloat from hprose context
func (*BaseContext) GetInt ¶
func (context *BaseContext) GetInt(key string) (value int, ok bool)
GetInt from hprose context
func (*BaseContext) GetInt64 ¶
func (context *BaseContext) GetInt64(key string) (value int64, ok bool)
GetInt64 from hprose context
func (*BaseContext) GetInterface ¶
func (context *BaseContext) GetInterface(key string) (value interface{}, ok bool)
GetInterface from hprose context
func (*BaseContext) GetString ¶
func (context *BaseContext) GetString(key string) (value string, ok bool)
GetString from hprose context
func (*BaseContext) GetUInt ¶
func (context *BaseContext) GetUInt(key string) (value uint, ok bool)
GetUInt from hprose context
func (*BaseContext) GetUInt64 ¶
func (context *BaseContext) GetUInt64(key string) (value uint64, ok bool)
GetUInt64 from hprose context
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 BaseService ¶
type BaseService struct { *Methods ServiceEvent DebugEnabled bool // contains filtered or unexported fields }
BaseService is the hprose base service
func NewBaseService ¶
func NewBaseService() (service *BaseService)
NewBaseService is the constructor for BaseService
func (*BaseService) AddFilter ¶
func (service *BaseService) AddFilter(filter Filter)
AddFilter add a filter
func (*BaseService) GetFilter ¶
func (service *BaseService) GetFilter() Filter
GetFilter return the first filter
func (*BaseService) Handle ¶
func (service *BaseService) Handle(data []byte, context Context) (output []byte)
Handle the hprose request and return the hprose response
func (*BaseService) RemoveFilter ¶
func (service *BaseService) RemoveFilter(filter Filter)
RemoveFilter remove a filter
func (*BaseService) SetFilter ¶
func (service *BaseService) SetFilter(filter Filter)
SetFilter set the only filter
type BufReader ¶
type BufReader interface { Read(p []byte) (n int, err error) ReadByte() (c byte, err error) ReadRune() (r rune, size int, err error) ReadString(delim byte) (line string, err error) }
BufReader is buffer reader interface, Hprose Reader use it as input stream.
type BufWriter ¶
type BufWriter interface { Write(p []byte) (n int, err error) WriteByte(c byte) error WriteRune(r rune) (n int, err error) WriteString(s string) (n int, err error) }
BufWriter is buffer writer interface, Hprose Writer use it as output stream.
type BytesReader ¶
BytesReader is a bytes reader
func NewBytesReader ¶
func NewBytesReader(b []byte) (reader *BytesReader)
NewBytesReader is the constructor of BytesReader
func (*BytesReader) Read ¶
func (r *BytesReader) Read(b []byte) (n int, err error)
Read bytes from BytesReader
func (*BytesReader) ReadByte ¶
func (r *BytesReader) ReadByte() (b byte, err error)
ReadByte from BytesReader
func (*BytesReader) ReadRune ¶
func (r *BytesReader) ReadRune() (ch rune, size int, err error)
ReadRune from BytesReader
func (*BytesReader) ReadString ¶
func (r *BytesReader) ReadString(delim byte) (line string, err error)
ReadString from BytesReader
type Client ¶
type Client interface { UseService(...interface{}) Invoke(string, []interface{}, *InvokeOptions, interface{}) <-chan error Uri() string SetUri(string) GetFilter() Filter SetFilter(filter Filter) AddFilter(filter Filter) RemoveFilter(filter Filter) TLSClientConfig() *tls.Config SetTLSClientConfig(config *tls.Config) SetKeepAlive(enable bool) Close() }
Client is hprose client
type ClientContext ¶
type ClientContext struct { *BaseContext Client }
ClientContext is the hprose client context
type ConnEntry ¶
ConnEntry is the connection entry in connection pool
func NewStreamConnEntry ¶
NewStreamConnEntry is the constructor for StreamConnEntry
type ConnPool ¶
type ConnPool interface { Timeout() time.Duration SetTimeout(d time.Duration) Get(uri string) ConnEntry Close(uri string) Free(entry ConnEntry) }
ConnPool is the connection pool
func NewStreamConnPool ¶
NewStreamConnPool is the constructor for StreamConnPool
type Context ¶
type Context interface { UserData() map[string]interface{} GetInt(key string) (value int, ok bool) GetUInt(key string) (value uint, ok bool) GetInt64(key string) (value int64, ok bool) GetUInt64(key string) (value uint64, ok bool) GetFloat(key string) (value float64, ok bool) GetBool(key string) (value bool, ok bool) GetString(key string) (value string, ok bool) GetInterface(key string) (value interface{}, ok bool) 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{}) }
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 HttpClient ¶
type HttpClient struct {
*BaseClient
}
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 return the compression status of hprose client
func (*HttpClient) Header ¶
func (client *HttpClient) Header() *http.Header
Header return the http.Header in hprose client
func (*HttpClient) Http ¶
func (client *HttpClient) Http() *http.Client
Http return the http.Client in hprose client
func (*HttpClient) KeepAlive ¶
func (client *HttpClient) KeepAlive() bool
KeepAlive return the keepalive status of hprose client
func (*HttpClient) MaxIdleConnsPerHost ¶
func (client *HttpClient) MaxIdleConnsPerHost() int
MaxIdleConnsPerHost return the max idle connections per host of hprose client
func (*HttpClient) SetCompression ¶
func (client *HttpClient) SetCompression(enable bool)
SetCompression set the compression status of hprose client
func (*HttpClient) SetKeepAlive ¶
func (client *HttpClient) SetKeepAlive(enable bool)
SetKeepAlive set the keepalive status of hprose client
func (*HttpClient) SetMaxIdleConnsPerHost ¶
func (client *HttpClient) SetMaxIdleConnsPerHost(value int)
SetMaxIdleConnsPerHost set the max idle connections per host of hprose client
func (*HttpClient) SetTLSClientConfig ¶
func (client *HttpClient) SetTLSClientConfig(config *tls.Config)
SetTLSClientConfig set the tls.Config
func (*HttpClient) SetUri ¶
func (client *HttpClient) SetUri(uri string)
SetUri set the uri of hprose client
func (*HttpClient) TLSClientConfig ¶
func (client *HttpClient) TLSClientConfig() *tls.Config
TLSClientConfig return the tls.Config in hprose client
type HttpContext ¶
type HttpContext struct { *BaseContext Response http.ResponseWriter Request *http.Request }
HttpContext is the hprose http context
type HttpService ¶
type HttpService struct { *BaseService P3PEnabled bool GetEnabled bool CrossDomainEnabled bool // 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) AddAccessControlAllowOrigin ¶
func (service *HttpService) AddAccessControlAllowOrigin(origin string)
AddAccessControlAllowOrigin add access control allow origin
func (*HttpService) ClientAccessPolicyXmlContent ¶
func (service *HttpService) ClientAccessPolicyXmlContent() []byte
ClientAccessPolicyXmlContent return the client access policy xml content
func (*HttpService) ClientAccessPolicyXmlFile ¶
func (service *HttpService) ClientAccessPolicyXmlFile() string
ClientAccessPolicyXmlFile return the client access policy xml file
func (*HttpService) CrossDomainXmlContent ¶
func (service *HttpService) CrossDomainXmlContent() []byte
CrossDomainXmlContent return the cross domain xml content
func (*HttpService) CrossDomainXmlFile ¶
func (service *HttpService) CrossDomainXmlFile() string
CrossDomainXmlFile return the cross domain xml file
func (*HttpService) RemoveAccessControlAllowOrigin ¶
func (service *HttpService) RemoveAccessControlAllowOrigin(origin string)
RemoveAccessControlAllowOrigin remove access control allow origin
func (*HttpService) Serve ¶
func (service *HttpService) Serve(response http.ResponseWriter, request *http.Request, userData map[string]interface{})
Serve ...
func (*HttpService) ServeHTTP ¶
func (service *HttpService) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP ...
func (*HttpService) SetClientAccessPolicyXmlContent ¶
func (service *HttpService) SetClientAccessPolicyXmlContent(content []byte)
SetClientAccessPolicyXmlContent set the client access policy xml content
func (*HttpService) SetClientAccessPolicyXmlFile ¶
func (service *HttpService) SetClientAccessPolicyXmlFile(filename string)
SetClientAccessPolicyXmlFile set the client access policy xml file
func (*HttpService) SetCrossDomainXmlContent ¶
func (service *HttpService) SetCrossDomainXmlContent(content []byte)
SetCrossDomainXmlContent set the cross domain xml content
func (*HttpService) SetCrossDomainXmlFile ¶
func (service *HttpService) SetCrossDomainXmlFile(filename string)
SetCrossDomainXmlFile set the cross domain xml file
type HttpServiceEvent ¶
type HttpServiceEvent interface { ServiceEvent OnSendHeader(context *HttpContext) }
HttpServiceEvent is the hprose http service event
type InvokeOptions ¶
type InvokeOptions struct { ByRef interface{} // true, false, nil SimpleMode interface{} // true, false, nil ResultMode ResultMode }
InvokeOptions is the invoke options of hprose client
type JSONRPCClientFilter ¶
type JSONRPCClientFilter struct {
Version string
}
JSONRPCClientFilter is a JSONRPC Client Filter
func NewJSONRPCClientFilter ¶
func NewJSONRPCClientFilter(version string) JSONRPCClientFilter
NewJSONRPCClientFilter is a constructor for JSONRPCClientFilter
func (JSONRPCClientFilter) InputFilter ¶
func (filter JSONRPCClientFilter) InputFilter(data []byte, context Context) []byte
InputFilter for JSONRPC Client
func (JSONRPCClientFilter) OutputFilter ¶
func (filter JSONRPCClientFilter) OutputFilter(data []byte, context Context) []byte
OutputFilter for JSONRPC Client
type JSONRPCServiceFilter ¶
type JSONRPCServiceFilter struct{}
JSONRPCServiceFilter is a JSONRPC Service Filter
func (JSONRPCServiceFilter) InputFilter ¶
func (filter JSONRPCServiceFilter) InputFilter(data []byte, context Context) []byte
InputFilter for JSONRPC Service
func (JSONRPCServiceFilter) OutputFilter ¶
func (filter JSONRPCServiceFilter) OutputFilter(data []byte, context Context) []byte
OutputFilter for JSONRPC Service
type Method ¶
type Method struct { Function reflect.Value ResultMode ResultMode SimpleMode bool }
Method is the publish service method
type Methods ¶
Methods is the publish service methods
func (*Methods) AddAllMethods ¶
func (methods *Methods) AddAllMethods(obj interface{}, options ...interface{})
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 (*Methods) AddFunction ¶
AddFunction publish a func or bound method name is the method name function is a func or bound method options is ResultMode, SimpleMode and prefix
func (*Methods) AddFunctions ¶
func (methods *Methods) AddFunctions(names []string, functions []interface{}, options ...interface{})
AddFunctions ... names are method names functions are funcs or bound methods options is the same as AddFuntion
func (*Methods) AddMethods ¶
func (methods *Methods) AddMethods(obj interface{}, options ...interface{})
AddMethods ... obj is service object. all the public method and func field will be published options is the same as AddFuntion
func (*Methods) AddMissingMethod ¶
func (methods *Methods) AddMissingMethod(method MissingMethod, options ...interface{})
AddMissingMethod ... All methods not explicitly published will be redirected to the method.
type MissingMethod ¶
MissingMethod is missing method
type RawReader ¶
type RawReader struct {
Stream BufReader
}
RawReader is the hprose raw reader
func NewRawReader ¶
NewRawReader is a constructor for RawReader
type Reader ¶
Reader is a fine-grained operation struct for Hprose unserialization when JSONCompatible is true, the Map data will unserialize to map[string]interface as the default type
func (*Reader) ReadBigIntWithoutTag ¶
ReadBigIntWithoutTag from stream
func (*Reader) ReadBytesWithoutTag ¶
ReadBytesWithoutTag from stream
func (*Reader) ReadDateTime ¶
ReadDateTime from stream
func (*Reader) ReadDateWithoutTag ¶
ReadDateWithoutTag from stream
func (*Reader) ReadFloat32 ¶
ReadFloat32 from stream
func (*Reader) ReadFloat32WithoutTag ¶
ReadFloat32WithoutTag from stream
func (*Reader) ReadFloat64 ¶
ReadFloat64 from stream
func (*Reader) ReadFloat64WithoutTag ¶
ReadFloat64WithoutTag from stream
func (*Reader) ReadInt16WithoutTag ¶
ReadInt16WithoutTag from stream
func (*Reader) ReadInt32WithoutTag ¶
ReadInt32WithoutTag from stream
func (*Reader) ReadInt64WithoutTag ¶
ReadInt64WithoutTag from stream
func (*Reader) ReadInt8WithoutTag ¶
ReadInt8WithoutTag from stream
func (*Reader) ReadIntWithoutTag ¶
ReadIntWithoutTag from stream
func (*Reader) ReadInteger ¶
ReadInteger from stream
func (*Reader) ReadListWithoutTag ¶
ReadListWithoutTag from stream
func (*Reader) ReadMapWithoutTag ¶
ReadMapWithoutTag from stream
func (*Reader) ReadObjectWithoutTag ¶
ReadObjectWithoutTag from stream
func (*Reader) ReadSliceWithoutTag ¶
ReadSliceWithoutTag from stream
func (*Reader) ReadStringWithoutTag ¶
ReadStringWithoutTag from stream
func (*Reader) ReadTimeWithoutTag ¶
ReadTimeWithoutTag from stream
func (*Reader) ReadUUIDWithoutTag ¶
ReadUUIDWithoutTag from stream
func (*Reader) ReadUint16WithoutTag ¶
ReadUint16WithoutTag from stream
func (*Reader) ReadUint32WithoutTag ¶
ReadUint32WithoutTag from stream
func (*Reader) ReadUint64WithoutTag ¶
ReadUint64WithoutTag from stream
func (*Reader) ReadUint8WithoutTag ¶
ReadUint8WithoutTag from stream
func (*Reader) ReadUintWithoutTag ¶
ReadUintWithoutTag from stream
func (*Reader) ReadUinteger ¶
ReadUinteger from stream
func (*Reader) Unserialize ¶
Unserialize a data from stream
type ResultMode ¶
type ResultMode int
ResultMode is result mode
func (ResultMode) String ¶
func (result_mode ResultMode) String() string
type ServiceEvent ¶
type ServiceEvent interface { OnBeforeInvoke(name string, args []reflect.Value, byref bool, context Context) OnAfterInvoke(name string, args []reflect.Value, byref bool, result []reflect.Value, context Context) OnSendError(err error, context Context) }
ServiceEvent is the service event
type StreamClient ¶
type StreamClient struct { *BaseClient // contains filtered or unexported fields }
StreamClient is base struct for TcpClient and UnixClient
func (*StreamClient) SetReadBuffer ¶
func (client *StreamClient) SetReadBuffer(bytes int)
SetReadBuffer sets the size of the operating system's receive buffer associated with the connection.
func (*StreamClient) SetReadTimeout ¶
func (client *StreamClient) SetReadTimeout(d time.Duration)
SetReadTimeout for stream client
func (*StreamClient) SetWriteBuffer ¶
func (client *StreamClient) SetWriteBuffer(bytes int)
SetWriteBuffer sets the size of the operating system's transmit buffer associated with the connection.
func (*StreamClient) SetWriteTimeout ¶
func (client *StreamClient) SetWriteTimeout(d time.Duration)
SetWriteTimeout for stream client
type StreamContext ¶
type StreamContext struct { *BaseContext net.Conn }
StreamContext is the hprose stream context for service
type StreamService ¶
type StreamService struct { *BaseService // contains filtered or unexported fields }
StreamService is the base service for TcpService and UnixService
func (*StreamService) SetReadBuffer ¶
func (service *StreamService) SetReadBuffer(bytes int)
SetReadBuffer for stream service
func (*StreamService) SetReadTimeout ¶
func (service *StreamService) SetReadTimeout(d time.Duration)
SetReadTimeout for stream service
func (*StreamService) SetTimeout ¶
func (service *StreamService) SetTimeout(d time.Duration)
SetTimeout for stream service
func (*StreamService) SetWriteBuffer ¶
func (service *StreamService) SetWriteBuffer(bytes int)
SetWriteBuffer for stream service
func (*StreamService) SetWriteTimeout ¶
func (service *StreamService) SetWriteTimeout(d time.Duration)
SetWriteTimeout for stream service
type TcpClient ¶
type TcpClient struct { *StreamClient // contains filtered or unexported fields }
TcpClient is hprose tcp client
func NewTcpClient ¶
NewTcpClient is the constructor of TcpClient
func (*TcpClient) SetConnPool ¶
SetConnPool can set separate StreamConnPool for the client
func (*TcpClient) SetKeepAlive ¶
SetKeepAlive sets whether the operating system should send keepalive messages on the connection.
func (*TcpClient) SetKeepAlivePeriod ¶
SetKeepAlivePeriod sets period between keep alives.
func (*TcpClient) SetLinger ¶
SetLinger sets the behavior of Close on a connection which still has data waiting to be sent or to be acknowledged.
If sec < 0 (the default), the operating system finishes sending the data in the background.
If sec == 0, the operating system discards any unsent or unacknowledged data.
If sec > 0, the data is sent in the background as with sec < 0. On some operating systems after sec seconds have elapsed any remaining unsent data may be discarded.
func (*TcpClient) SetNoDelay ¶
SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.
func (*TcpClient) SetTLSClientConfig ¶
SetTLSClientConfig sets the Config structure used to configure a TLS client
func (*TcpClient) SetTimeout ¶
SetTimeout for connection in client pool
func (*TcpClient) TLSClientConfig ¶
TLSClientConfig returns the Config structure used to configure a TLS client
type TcpServer ¶
type TcpServer struct { *TcpService URL string // contains filtered or unexported fields }
TcpServer is a hprose tcp server
func NewTcpServer ¶
NewTcpServer is a constructor for TcpServer
type TcpService ¶
type TcpService struct { *StreamService // contains filtered or unexported fields }
TcpService is the hprose tcp service
func NewTcpService ¶
func NewTcpService() (service *TcpService)
NewTcpService is the constructor of TcpService
func (*TcpService) ServeTCP ¶
func (service *TcpService) ServeTCP(conn *net.TCPConn) (err error)
ServeTCP ...
func (*TcpService) SetKeepAlive ¶
func (service *TcpService) SetKeepAlive(keepalive bool)
SetKeepAlive sets whether the operating system should send keepalive messages on the connection.
func (*TcpService) SetKeepAlivePeriod ¶
func (service *TcpService) SetKeepAlivePeriod(d time.Duration)
SetKeepAlivePeriod sets period between keep alives.
func (*TcpService) SetLinger ¶
func (service *TcpService) SetLinger(sec int)
SetLinger sets the behavior of Close on a connection which still has data waiting to be sent or to be acknowledged.
If sec < 0 (the default), the operating system finishes sending the data in the background.
If sec == 0, the operating system discards any unsent or unacknowledged data.
If sec > 0, the data is sent in the background as with sec < 0. On some operating systems after sec seconds have elapsed any remaining unsent data may be discarded.
func (*TcpService) SetNoDelay ¶
func (service *TcpService) SetNoDelay(noDelay bool)
SetNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm). The default is true (no delay), meaning that data is sent as soon as possible after a Write.
func (*TcpService) SetTLSConfig ¶
func (service *TcpService) SetTLSConfig(config *tls.Config)
SetTLSConfig sets the Config structure used to configure TLS service
type Transporter ¶
Transporter is the hprose client transporter
type UUID ¶
type UUID []byte
UUID type is only a UUID wrapper for hprose serialize/unserialize, If you want to generate UUIDs, you should use other UUID package.
type UnixClient ¶
type UnixClient struct { *StreamClient // contains filtered or unexported fields }
UnixClient is hprose unix client
func NewUnixClient ¶
func NewUnixClient(uri string) (client *UnixClient)
NewUnixClient is the constructor of UnixClient
func (*UnixClient) SetConnPool ¶
func (client *UnixClient) SetConnPool(connPool ConnPool)
SetConnPool can set separate StreamConnPool for the client
func (*UnixClient) SetKeepAlive ¶
func (client *UnixClient) SetKeepAlive(keepalive bool)
SetKeepAlive do nothing on unix client
func (*UnixClient) SetTLSClientConfig ¶
func (client *UnixClient) SetTLSClientConfig(config *tls.Config)
SetTLSClientConfig sets the Config structure used to configure a TLS client
func (*UnixClient) SetTimeout ¶
func (client *UnixClient) SetTimeout(d time.Duration)
SetTimeout for connection in client pool
func (*UnixClient) SetUri ¶
func (client *UnixClient) SetUri(uri string)
SetUri set the uri of hprose client
func (*UnixClient) TLSClientConfig ¶
func (client *UnixClient) TLSClientConfig() *tls.Config
TLSClientConfig returns the Config structure used to configure a TLS client
func (*UnixClient) Timeout ¶
func (client *UnixClient) Timeout() time.Duration
Timeout return the timeout of the connection in client pool
type UnixServer ¶
type UnixServer struct { *UnixService URL string // contains filtered or unexported fields }
UnixServer is a hprose unix server
func NewUnixServer ¶
func NewUnixServer(uri string) (server *UnixServer)
NewUnixServer is a constructor for UnixServer
func (*UnixServer) Handle ¶
func (server *UnixServer) Handle() (err error)
Handle the hprose unix server
func (*UnixServer) Start ¶
func (server *UnixServer) Start() (err error)
Start the hprose unix server
type UnixService ¶
type UnixService StreamService
UnixService is the hprose unix service
func NewUnixService ¶
func NewUnixService() *UnixService
NewUnixService is the constructor of UnixService
type WebSocketClient ¶
type WebSocketClient struct {
*BaseClient
}
WebSocketClient is hprose websocket client
func NewWebSocketClient ¶
func NewWebSocketClient(uri string) (client *WebSocketClient)
NewWebSocketClient is the constructor of WebSocketClient
func (*WebSocketClient) Header ¶
func (client *WebSocketClient) Header() *http.Header
Header returns the http.Header in hprose client
func (*WebSocketClient) MaxConcurrentRequests ¶
func (client *WebSocketClient) MaxConcurrentRequests() int
MaxConcurrentRequests returns the max concurrent requests of hprose client
func (*WebSocketClient) SetKeepAlive ¶
func (client *WebSocketClient) SetKeepAlive(enable bool)
SetKeepAlive do nothing on WebSocketClient, it is always keepAlive
func (*WebSocketClient) SetMaxConcurrentRequests ¶
func (client *WebSocketClient) SetMaxConcurrentRequests(value int)
SetMaxConcurrentRequests sets the max concurrent requests of hprose client
func (*WebSocketClient) SetTLSClientConfig ¶
func (client *WebSocketClient) SetTLSClientConfig(config *tls.Config)
SetTLSClientConfig sets the tls.Config
func (*WebSocketClient) SetUri ¶
func (client *WebSocketClient) SetUri(uri string)
SetUri set the uri of hprose client
func (*WebSocketClient) TLSClientConfig ¶
func (client *WebSocketClient) TLSClientConfig() *tls.Config
TLSClientConfig returns the tls.Config in hprose client
type WebSocketContext ¶
type WebSocketContext struct { *HttpContext WebSocket *websocket.Conn }
WebSocketContext is the hprose websocket context
type WebSocketService ¶
type WebSocketService struct { *HttpService *websocket.Upgrader }
WebSocketService is the hprose websocket service
func NewWebSocketService ¶
func NewWebSocketService() *WebSocketService
NewWebSocketService is the constructor of WebSocketService
func (*WebSocketService) ServeHTTP ¶
func (service *WebSocketService) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServeHTTP ...
type Writer ¶
type Writer struct { Stream BufWriter // contains filtered or unexported fields }
Writer is a fine-grained operation struct for Hprose serialization
func (*Writer) WriteArray ¶
WriteArray to stream
func (*Writer) WriteBigInt ¶
WriteBigInt to stream
func (*Writer) WriteBytes ¶
WriteBytes to stream
func (*Writer) WriteBytesWithRef ¶
WriteBytesWithRef to stream
func (*Writer) WriteFloat64 ¶
WriteFloat64 to stream
func (*Writer) WriteString ¶
WriteString to stream
func (*Writer) WriteStringWithRef ¶
WriteStringWithRef to stream
func (*Writer) WriteUint64 ¶
WriteUint64 to stream
Source Files ¶
- 1_1_compatible.go
- class_manager.go
- client.go
- context.go
- doc.go
- filter.go
- formatter.go
- http_client.go
- http_service.go
- jsonrpc_client_filter.go
- jsonrpc_service_filter.go
- raw_reader.go
- reader.go
- result_mode.go
- service.go
- stream_client.go
- stream_common.go
- stream_service.go
- tags.go
- tcp_client.go
- tcp_service.go
- unix_client.go
- unix_service.go
- uuid.go
- websocket_client.go
- websocket_service.go
- writer.go
Directories ¶
Path | Synopsis |
---|---|
Package hprose client example: package main import ( "fmt" "hprose" ) type testUser struct { Name string Sex int Birthday time.Time Age int Married bool } type testRemoteObject struct { Hello func(string) string HelloWithError func(string) (string, error) `name:"hello"` AsyncHello func(string) <-chan string `name:"hello"` AsyncHelloWithError func(string) (<-chan string, <-chan error) `name:"hello"` Sum func(...int) int SwapKeyAndValue func(*map[string]string) map[string]string `byref:"true"` SwapInt func(int, int) (int, int) `name:"swap"` SwapFloat func(float64, float64) (float64, float64) `name:"swap"` Swap func(interface{}, interface{}) (interface{}, interface{}) GetUserList func() []testUser } func main() { client := hprose.NewClient("http://www.hprose.com/example/") var ro *RemoteObject client.UseService(&ro) // If an error occurs, it will panic fmt.Println(ro.Hello("World")) // If an error occurs, an error value will be returned if result, err := ro.HelloWithError("World"); err == nil { fmt.Println(result) } else { fmt.Println(err.Error()) } // If an error occurs, it will be ignored result := ro.AsyncHello("World") fmt.Println(<-result) // If an error occurs, an error chan will be returned result, err := ro.AsyncHelloWithError("World") if e := <-err; e == nil { fmt.Println(<-result) } else { fmt.Println(e.Error()) } fmt.Println(ro.Sum(1, 2, 3, 4, 5)) m := make(map[string]string) m["Jan"] = "January" m["Feb"] = "February" m["Mar"] = "March" m["Apr"] = "April" m["May"] = "May" m["Jun"] = "June" m["Jul"] = "July" m["Aug"] = "August" m["Sep"] = "September" m["Oct"] = "October" m["Nov"] = "November" m["Dec"] = "December" fmt.Println(m) mm := ro.SwapKeyAndValue(&m) fmt.Println(m) fmt.Println(mm) fmt.Println(ro.GetUserList()) fmt.Println(ro.SwapInt(1, 2)) fmt.Println(ro.SwapFloat(1.2, 3.4)) fmt.Println(ro.Swap("Hello", "World")) }
|
Package hprose client example: package main import ( "fmt" "hprose" ) type testUser struct { Name string Sex int Birthday time.Time Age int Married bool } type testRemoteObject struct { Hello func(string) string HelloWithError func(string) (string, error) `name:"hello"` AsyncHello func(string) <-chan string `name:"hello"` AsyncHelloWithError func(string) (<-chan string, <-chan error) `name:"hello"` Sum func(...int) int SwapKeyAndValue func(*map[string]string) map[string]string `byref:"true"` SwapInt func(int, int) (int, int) `name:"swap"` SwapFloat func(float64, float64) (float64, float64) `name:"swap"` Swap func(interface{}, interface{}) (interface{}, interface{}) GetUserList func() []testUser } func main() { client := hprose.NewClient("http://www.hprose.com/example/") var ro *RemoteObject client.UseService(&ro) // If an error occurs, it will panic fmt.Println(ro.Hello("World")) // If an error occurs, an error value will be returned if result, err := ro.HelloWithError("World"); err == nil { fmt.Println(result) } else { fmt.Println(err.Error()) } // If an error occurs, it will be ignored result := ro.AsyncHello("World") fmt.Println(<-result) // If an error occurs, an error chan will be returned result, err := ro.AsyncHelloWithError("World") if e := <-err; e == nil { fmt.Println(<-result) } else { fmt.Println(e.Error()) } fmt.Println(ro.Sum(1, 2, 3, 4, 5)) m := make(map[string]string) m["Jan"] = "January" m["Feb"] = "February" m["Mar"] = "March" m["Apr"] = "April" m["May"] = "May" m["Jun"] = "June" m["Jul"] = "July" m["Aug"] = "August" m["Sep"] = "September" m["Oct"] = "October" m["Nov"] = "November" m["Dec"] = "December" fmt.Println(m) mm := ro.SwapKeyAndValue(&m) fmt.Println(m) fmt.Println(mm) fmt.Println(ro.GetUserList()) fmt.Println(ro.SwapInt(1, 2)) fmt.Println(ro.SwapFloat(1.2, 3.4)) fmt.Println(ro.Swap("Hello", "World")) } |