roc

package module
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: Apache-2.0 Imports: 26 Imported by: 0

README ΒΆ

Roc

logo

GitHub Workflow Status Go Report Card Go Reference GitHub GitHub release (latest SemVer including pre-releases)

πŸ‘‹ Roc is a rpc micro framework,it designed with go,and transport protocol by rsocket-go.


IT IS UNDER ACTIVE DEVELOPMENT, APIs are unstable and maybe change at any time until release of v1.0.0.

πŸ‘€ Features
  • Simple to use ✨
  • Lightweight ✨
  • High performance ✨
  • Service discovery ✨
  • Support websocket and socket same time ✨
  • Support json or gogo proto when use rpc ✨
🌱 Quick start
  • first you must install proto and etcd

  • install protoc-gen-roc

    go env -w GO111MODULE = on
    go get github.com/go -roc/roc/cmd/protoc-gen-roc
    protoc --roc_out = plugins = roc:.*.proto
  • run a roc service
package main

import (
    "fmt"

    "github.com/coreos/etcd/clientv3"

    "github.com/go-roc/roc"
    "github.com/go-roc/roc/_auxiliary/example/tutorials/proto/pbhello"
    "github.com/go-roc/roc/_auxiliary/example/tutorials/srv/srv.hello/hello"
)

func main() {
    var s = roc.NewService(
        roc.TCPAddress("127.0.0.1:8888"),
        roc.Namespace("srv.hello"),
        roc.EtcdConfig(
            &clientv3.Config{
                Endpoints: []string{"127.0.0.1:2379"},
            }
        ),
    )
    pbhello.RegisterHelloWorldServer(s, &hello.Hello{})
    if err := s.Run(); err != nil {
        fmt.Println(err)
    }
}
  • config help
package main

import (
    "fmt"

    "github.com/go-roc/roc/config"

    _ "github.com/go-roc/roc/etcd/mock"
)

func main() {

    //new config use default option
    err := config.NewConfig()
    if err != nil {
        panic(err)
    }

    const key = "test"
    var result struct {
        Name string `json:"name"`
        Age  int    `json:"age"`
    }

    simple(key, &result)
    coverPublic(key, &result)
}

//put key/value to etcd:
//go:generate etcdctl configroc/v1.0.0/public/roc.test { "name":"roc", "age":17 }
func simple(key string, v interface{}) {
    //simple public use
    //the key is roc.test
    err := config.DecodePublic(key, v)
    if err != nil {
        panic(err)
    }

    fmt.Println("------", v)
    //output: ------ {roc 17}
}

//put key/value to etcd:
//go:generate etcdctl configroc/v1.0.0/private/roc.test { "name":"roc", "age":18 }
func coverPublic(key string, v interface{}) {
    //the key is roc.test
    //cover public by private
    err := config.DecodePublic(key, v)
    if err != nil {
        panic(err)
    }

    fmt.Println("------", v)
    //output: ------ {roc 18}
}

πŸ’žοΈ see more example for more help.
πŸ“« How to reach me by email ...
  1743299@qq.com

code

✨ TODO ✨
  • bench test
  • sidecar
  • more example
  • more singleton tests
  • generate dir
  • command for request service
  • sidecar service
  • config service
  • broker redirect request service
  • logger service
  • simple service GUI

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	// StateBlock block is unavailable state
	StateBlock state = 0x01 + iota
	// StateReady ready is unavailable state
	StateReady

	// StateWorking is available state
	StateWorking
)
View Source
const SupportPackageIsVersion1 = 1

Variables ΒΆ

View Source
var (
	ErrorNoneServer   = errors.New("server is none to use")
	ErrorNoSuchServer = errors.New("no such server")
)

Functions ΒΆ

This section is empty.

Types ΒΆ

type Conn ΒΆ

type Conn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Conn include transport client

func (*Conn) Client ΒΆ

func (c *Conn) Client() transport.Client

Client get client

func (*Conn) Close ΒΆ

func (c *Conn) Close()

Close close client

type Invoke ΒΆ

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

type InvokeOption ΒΆ

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

type InvokeOptions ΒΆ

type InvokeOptions func(*InvokeOption)

func InvokeBuffSize ΒΆ

func InvokeBuffSize(buffSize int) InvokeOptions

InvokeBuffSize set buff size for requestChannel

func WithAddress ΒΆ

func WithAddress(name, address string, version ...string) InvokeOptions

WithAddress set service discover prefix with both service serviceName and address

func WithName ΒΆ

func WithName(name string, version ...string) InvokeOptions

WithName set service discover prefix with service serviceName

func WithTracing ΒΆ

func WithTracing(t string) InvokeOptions

WithTracing set tracing

type Option ΒΆ

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

type Options ΒΆ

type Options func(option *Option)

func BuffSize ΒΆ

func BuffSize(buffSize int) Options

func Codec ΒΆ

func Codec(cc codec.Codec) Options

func ConfigOption ΒΆ

func ConfigOption(opts ...config.Options) Options

func ConnectTimeout ΒΆ

func ConnectTimeout(connectTimeout time.Duration) Options

ConnectTimeout set connect timeout

func E ΒΆ

func Error ΒΆ

func Error(err parcel.ErrorPackager) Options

func EtcdConfig ΒΆ

func EtcdConfig(e *clientv3.Config) Options

EtcdConfig setting global etcd config first

func Exit ΒΆ

func Exit(exit ...func()) Options

func Id ΒΆ

func Id(id string) Options

func KeepaliveInterval ΒΆ

func KeepaliveInterval(keepaliveInterval time.Duration) Options

KeepaliveInterval set keepalive interval

func KeepaliveLifetime ΒΆ

func KeepaliveLifetime(keepaliveLifetime time.Duration) Options

KeepaliveLifetime set keepalive life time

func Namespace ΒΆ

func Namespace(name string) Options

func Port ΒΆ

func Port(port [2]int) Options

func Signal ΒΆ

func Signal(signal ...os.Signal) Options

func TCPAddress ΒΆ

func TCPAddress(address string) Options

func Version ΒΆ

func Version(version string) Options

func Wrapper ΒΆ

func Wrapper(wrappers ...parcel.Wrapper) Options

func WssAddress ΒΆ

func WssAddress(address, path string) Options

type Service ΒΆ

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

func NewService ΒΆ

func NewService(opts ...Options) *Service

func (*Service) Close ΒΆ

func (s *Service) Close()

func (*Service) Codec ΒΆ

func (s *Service) Codec() codec.Codec

func (*Service) InvokeRC ΒΆ

func (s *Service) InvokeRC(
	c *context.Context,
	method string,
	req chan []byte,
	errIn chan error,
	opts ...InvokeOptions,
) (chan []byte, chan error)

InvokeRC rpc request requestChannel,it's multiple request and multiple response

func (*Service) InvokeRR ΒΆ

func (s *Service) InvokeRR(c *context.Context, method string, req, rsp proto.Message, opts ...InvokeOptions) error

InvokeRR rpc request requestResponse,it's block request,one request one response

func (*Service) InvokeRS ΒΆ

func (s *Service) InvokeRS(c *context.Context, method string, req proto.Message, opts ...InvokeOptions) (
	chan []byte,
	chan error,
)

InvokeRS rpc request requestStream,it's one request and multiple response

func (*Service) RegisterChannelHandler ΒΆ

func (s *Service) RegisterChannelHandler(method string, rs parcel.ChannelHandler)

func (*Service) RegisterHandler ΒΆ

func (s *Service) RegisterHandler(method string, rr parcel.Handler)

func (*Service) RegisterStreamHandler ΒΆ

func (s *Service) RegisterStreamHandler(method string, rs parcel.StreamHandler)

func (*Service) Run ΒΆ

func (s *Service) Run() error

type Strategy ΒΆ

type Strategy interface {

	//Next Round-robin scheduling
	Next(scope string) (next *Conn, err error)

	//Straight direct call
	Straight(scope, address string) (next *Conn, err error)

	//Close Strategy
	Close()
}

Jump to

Keyboard shortcuts

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