Roc
π 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
GO111MODULE= on go get github.com/go -roc/roc/cmd/protoc-gen-roc
protoc --roc_out = plugins = roc:.*.proto
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)
}
}
package main
import (
"fmt"
"github.com/go-roc/roc/config"
_ "github.com/go-roc/roc/internal/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"`
}
coverPublic(key, &result)
coverPrivate(key, &result)
}
//put key/value to etcd:
//go:generate etcdctl put configroc/v1.0.0/public/roc.test "{ "name":"roc", "age":18 }"
func coverPublic(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 18}
}
//put key/value to etcd:
//go:generate etcdctl put configroc/v1.0.0/private/test "{ "name":"roc", "age":18 }"
func coverPrivate(key string, v interface{}) {
//the key is test
err := config.DecodePrivate(key, v)
if err != nil {
panic(err)
}
fmt.Println("------", v)
//output: ------ {roc 18}
}
ποΈ see more example for more help.
π« How to reach me and be a contributor ...
β¨ 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