goridge

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 8 Imported by: 14

README

Goridge, high performance PHP-to-Golang net/rpc codec

Latest Stable Version GoDoc License Build Status Scrutinizer Code Quality Coverage Status

Goridge is high performance PHP-to-Golang codec library which works over native PHP sockets and Golang net/rpc package. The library allows you to call Go service methods from PHP with minimal footprint, structures and []byte support.

Features

  • no external dependencies or services, drop-in
  • low message footprint (9 bytes over any binary payload)
  • sockets over TCP or Unix
  • very fast (260k calls per second on Ryzen 1700X over 25 threads)
  • native net/rpc integration, ability to connect to existed application(s)
  • structured data transfer using json
  • []byte transfer, including big payloads
  • service, message and transport level error handling
  • hackable
  • works on Windows

Examples

<?php
use Spiral\Goridge;
require "vendor/autoload.php";

$rpc = new Goridge\JsonRPC(new Goridge\Connection("127.0.0.1", 6001));

echo $rpc->call("App.Hi", "Antony");
package main

import (
	"fmt"
	"github.com/spiral/goridge"
	"net"
	"net/rpc"
)

type App struct{}

func (s *App) Hi(name string, r *string) error {
	*r = fmt.Sprintf("Hello, %s!", name)
	return nil
}

func main() {
	ln, err := net.Listen("tcp", ":6001")
	if err != nil {
		panic(err)
	}

	rpc.Register(new(App))

	for {
		conn, err := ln.Accept()
		if err != nil {
			continue
		}
		go rpc.ServeCodec(goridge.NewJSONCodec(conn))
	}
}
$ go get "github.com/spiral/goridge"

See tests folder for more examples.

Check this libraries in order to find suitable socket manager:

Documentation

Index

Constants

View Source
const (
	KeepConnection  = 0
	CloseConnection = 1
	NoBody          = 16
	RawBody         = 32
	ErrorBody       = 64
)
View Source
const (
	ChunkSize = 655336
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONCodec

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

A JSONCodec implements ServeCodec using 9 bytes data prefixes and body marshaling via json.

func NewJSONCodec

func NewJSONCodec(conn io.ReadWriteCloser) *JSONCodec

NewJSONCodec initiates new JSONCodec over given connection.

func (*JSONCodec) Close

func (c *JSONCodec) Close() error

Close underlying socket.

func (*JSONCodec) ReadRequestBody

func (c *JSONCodec) ReadRequestBody(out interface{}) error

ReadRequestBody fetches prefixed body payload and automatically unmarshal it as json. RawBody flag will populate []byte lice argument for rpc method.

func (*JSONCodec) ReadRequestHeader

func (c *JSONCodec) ReadRequestHeader(r *rpc.Request) error

ReadRequestHeader request metadata.

func (*JSONCodec) WriteResponse

func (c *JSONCodec) WriteResponse(r *rpc.Response, body interface{}) error

WriteResponse marshaled response, byte slice or error to remote party.

type Prefix

type Prefix []byte

Prefix is always 9 bytes long and contain meta flags and length of next data package.

func (Prefix) Flags

func (p Prefix) Flags() byte

func (Prefix) HasBody

func (p Prefix) HasBody() bool

func (Prefix) SetFlags

func (p Prefix) SetFlags(flags byte)

func (Prefix) SetSize

func (p Prefix) SetSize(size uint64)

func (Prefix) Size

func (p Prefix) Size() uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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