roc

package module
v1.0.0 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()
}

Directories

Path Synopsis
_auxiliary
example/config command
example/rsync command
cmd
protoc-gen-roc command
roctl/project
enable project default generator
enable project default generator
internal
sig
metadata
Package metadata for websocket or socket from rsocket-rpc-go Metadata
Package metadata for websocket or socket from rsocket-rpc-go Metadata
log
test command
x
fs

Jump to

Keyboard shortcuts

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