Documentation ¶
Index ¶
- func Dial(network, address string) (*rpc.Client, error)
- func NewClient(conn io.ReadWriteCloser) *rpc.Client
- func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec
- func NewHTTPNameServerCodec(name string, conn io.ReadWriteCloser, w http.ResponseWriter, req *http.Request) rpc.ServerCodec
- func NewHTTPServerCodec(conn io.ReadWriteCloser, w http.ResponseWriter, req *http.Request) rpc.ServerCodec
- func NewNameServerCodec(name string, conn io.ReadWriteCloser) rpc.ServerCodec
- func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec
- type Header
- type Packager
- type Request
- type Response
- type YHClient
- type YarServer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
Dial connects to a YAR-RPC server at the specified network address.
Example ¶
// YarTCPClient client, err := goyar.Dial("tcp", "127.0.0.1:1234") if err != nil { log.Fatal("dialing:", err) } err := client.Call("Set", 15, &r)
Output:
func NewClient ¶
func NewClient(conn io.ReadWriteCloser) *rpc.Client
NewClient returns a new rpc.Client to handle requests to the set of services at the other end of the connection.
func NewClientCodec ¶
func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec
NewClientCodec returns a new rpc.ClientCodec using YAR-RPC on conn.
func NewHTTPNameServerCodec ¶
func NewHTTPNameServerCodec(name string, conn io.ReadWriteCloser, w http.ResponseWriter, req *http.Request) rpc.ServerCodec
NewHTTPNameServerCodec returns a new rpc.ServerCodec using YAR-RPC on http conn.
func NewHTTPServerCodec ¶
func NewHTTPServerCodec(conn io.ReadWriteCloser, w http.ResponseWriter, req *http.Request) rpc.ServerCodec
NewHTTPServerCodec returns a new rpc.ServerCodec using YAR-RPC on http conn.
func NewNameServerCodec ¶
func NewNameServerCodec(name string, conn io.ReadWriteCloser) rpc.ServerCodec
NewNameServerCodec returns a new rpc.ServerCodec using YAR-RPC on tcp conn.
func NewServerCodec ¶
func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec
NewServerCodec returns a new rpc.ServerCodec using YAR-RPC on tcp conn.
Types ¶
type Header ¶
type Header struct { ID uint32 // transaction id Version uint16 // protocl version MagicNum uint32 // default is: 0x80DFEC60 Reserved uint32 Provider [32]byte // reqeust from who Token [32]byte // request token, used for authentication BodyLen uint32 // request body len PkgName Packager // body encode name }
Header Yar transport Header(90 bytes)
type Packager ¶
type Packager [8]byte
Packager yar packager name
type Request ¶
type Request struct { ID uint32 `json:"i"` // yar rpc id Method string `json:"m"` // calling method name Params []interface{} `json:"p"` // all the params }
Request yar request struct(only for json)
type Response ¶
type Response struct { ID uint32 `json:"i"` // yar rpc id Status int32 `json:"s"` // return status code Result interface{} `json:"r"` // return value Output string `json:"o"` // the called function standard output Error string `json:"e"` // return error message }
Response yar response struct(only for json)
type YHClient ¶
type YHClient struct {
// contains filtered or unexported fields
}
YHClient yar http client
func NewYHClient ¶
NewYHClient returns a new yar http client
Example ¶
package main import ( "fmt" "github.com/neverlee/goyar" ) func main() { // YarHTTPClient client := goyar.NewYHClient("http://yarserver/api.php", nil) var r int if err := client.MCall("multi", &r, 3, 4); err == nil { fmt.Println(r) } if err := client.Call("Set", 10, &r); err == nil { fmt.Println(r) } }
Output:
func (*YHClient) Call ¶
Call calling the remote yarrpc, only support one param. print the output and set return value
type YarServer ¶
YarServer yar rpc server
func (*YarServer) HandleHTTP ¶
HandleHTTP registers an HTTP handler for YAR RPC messages on rpcPath, It is still necessary to invoke http.Serve(), typically in a go statement.
func (*YarServer) Register ¶
func (y *YarServer) Register(rcvr interface{})
Register publishes in the server the set of methods of the receiver value. Default register name is 'yar'
func (*YarServer) ServeConn ¶
func (y *YarServer) ServeConn(conn io.ReadWriteCloser)
ServeConn runs the YAR-RPC server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.