Browse Source

stuff

Signed-off-by: Erik Hollensbe <github@hollensbe.org>
master
Erik Hollensbe 2 years ago
commit
32a3b1526b
  1. 13
      .gitignore
  2. 55
      Makefile
  3. 32
      box.rb
  4. 3
      entrypoint.sh
  5. 48
      example/example.go
  6. 155
      example/messages.pb.go
  7. 8
      example/messages.proto
  8. 11
      go.mod
  9. 38
      go.sum
  10. 113
      router.go
  11. 155
      router.pb.go
  12. 8
      router.proto

13
.gitignore

@ -0,0 +1,13 @@
.bash_history
.bashrc
.go-cache
.sqlite_history
.local
build
*.db
*.tar.gz
version/generated.go
*.pem
*.crt
*.key
.cache

55
Makefile

@ -0,0 +1,55 @@
IMAGE_NAME ?= natsrouter:testing
CODE_PATH ?= /go/src/code.hollensbe.org/erikh/natsrouter
GO_TEST := go test -v ./... -race -count 1
VERSION ?= $(shell git rev-parse HEAD)
DOCKER_CMD := docker run -it \
--rm \
-e IN_DOCKER=1 \
-e SETUID=$$(id -u) \
-e SETGID=$$(id -g) \
-w $(CODE_PATH) \
-v ${PWD}/.go-cache:/tmp/go-build-cache \
-v ${PWD}:$(CODE_PATH) \
$(IMAGE_NAME)
release: distclean
GOBIN=${PWD}/build/ldhcpd-$$(cat VERSION) VERSION=$$(cat VERSION) make install
# FIXME include LICENSE.md
cp README.md example.conf build/ldhcpd-$$(cat VERSION)
cd build && tar cvzf ../ldhcpd-$$(cat ../VERSION).tar.gz ldhcpd-$$(cat ../VERSION)
distclean:
rm -rf build
generate:
GOBIN=${GOPATH}/bin go install -v github.com/golang/protobuf/protoc-gen-go
VERSION=${VERSION} go generate -v ./...
shell: build
mkdir -p .go-cache
$(DOCKER_CMD)
build: get-box
box -t $(IMAGE_NAME) box.rb
docker-check:
@if [ -z "$${IN_DOCKER}" ]; then echo "You really don't want to do this"; exit 1; fi
start: docker-check stop
nats-server &
stop: docker-check
pkill nats-server || :
get-box:
@if [ ! -f "$(shell which box)" ]; \
then \
echo "Need to install box to build the docker images we use. Requires root access."; \
curl -sSL box-builder.sh | sudo bash; \
fi
test:
if [ -z "$${IN_DOCKER}" ]; then make build && $(DOCKER_CMD) $(GO_TEST); else $(GO_TEST); fi
.PHONY: test

32
box.rb

@ -0,0 +1,32 @@
from "golang:latest"
PROTOC_VERSION = "3.11.4"
PROTOC_URL = "https://github.com/protocolbuffers/protobuf/releases/download/v#{PROTOC_VERSION}/protoc-#{PROTOC_VERSION}-linux-x86_64.zip"
NATS_VERSION = "2.1.6"
NATS_URL = "https://github.com/nats-io/nats-server/releases/download/v#{NATS_VERSION}/nats-server-v#{NATS_VERSION}-linux-amd64.zip"
def download(name, url)
run "curl -sSL -o /#{name} '#{url}'"
yield "/#{name}"
run "rm -f /#{name}"
end
run "apt update && apt install sudo unzip -y"
run %q[grep -vE 'env_reset|secure_path' /etc/sudoers >tmp && mv tmp /etc/sudoers]
run %q[echo 'username ALL=(ALL:ALL) NOPASSWD:ALL' >>/etc/sudoers]
download("protoc.zip", PROTOC_URL) do |path|
run "unzip #{path} -d /usr"
run "chmod -R 755 /usr/bin/protoc /usr/include/google"
end
download("nats-server.zip", NATS_URL) do |path|
run "unzip #{path} -d /tmp"
run "mv /tmp/nats-server-v#{NATS_VERSION}-linux-amd64/nats-server /usr/bin"
run "chmod 755 /usr/bin/nats-server"
end
copy "entrypoint.sh", "/entrypoint.sh"
run "chmod 755 /entrypoint.sh"
set_exec entrypoint: %w[sh /entrypoint.sh], cmd: %w[bash]

3
entrypoint.sh

@ -0,0 +1,3 @@
groupadd -g "$SETGID" groupname
useradd -d "$PWD" -u "$SETUID" -g "$SETGID" -G sudo username
exec sudo -EH -u username "$@"

48
example/example.go

@ -0,0 +1,48 @@
package main
import (
"context"
"fmt"
"time"
"code.hollensbe.org/erikh/natsrouter"
"github.com/nats-io/nats.go"
"google.golang.org/protobuf/proto"
)
//go:generate protoc --proto_path=.:$GOPATH/src --go_out=. messages.proto
func main() {
r := natsrouter.NewRouter()
r.HandleFunc("foo", natsrouter.Handler{
Func: func(ctx context.Context, msg proto.Message) {
foo := msg.(*Foo)
fmt.Println(foo.Id, foo.Message)
},
InputTypeFunc: func() proto.Message { return &Foo{} },
})
conn, err := nats.Connect("localhost:4222")
if err != nil {
panic(err)
}
sub, err := conn.SubscribeSync("router")
if err != nil {
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())
go r.Handle(ctx, sub)
p := r.GetPublisher(conn, "router")
for i := 0; i < 1000; i++ {
if err := p.Publish("foo", &Foo{Id: int64(i), Message: "hello, world"}); err != nil {
panic(err)
}
}
time.Sleep(2 * time.Second)
cancel()
}

155
example/messages.pb.go

@ -0,0 +1,155 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.22.0
// protoc v3.11.4
// source: messages.proto
package main
import (
proto "github.com/golang/protobuf/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type Foo struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *Foo) Reset() {
*x = Foo{}
if protoimpl.UnsafeEnabled {
mi := &file_messages_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Foo) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Foo) ProtoMessage() {}
func (x *Foo) ProtoReflect() protoreflect.Message {
mi := &file_messages_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Foo.ProtoReflect.Descriptor instead.
func (*Foo) Descriptor() ([]byte, []int) {
return file_messages_proto_rawDescGZIP(), []int{0}
}
func (x *Foo) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *Foo) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
var File_messages_proto protoreflect.FileDescriptor
var file_messages_proto_rawDesc = []byte{
0x0a, 0x0e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x22, 0x2f, 0x0a, 0x03, 0x46, 0x6f, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x3b, 0x6d, 0x61, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
}
var (
file_messages_proto_rawDescOnce sync.Once
file_messages_proto_rawDescData = file_messages_proto_rawDesc
)
func file_messages_proto_rawDescGZIP() []byte {
file_messages_proto_rawDescOnce.Do(func() {
file_messages_proto_rawDescData = protoimpl.X.CompressGZIP(file_messages_proto_rawDescData)
})
return file_messages_proto_rawDescData
}
var file_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_messages_proto_goTypes = []interface{}{
(*Foo)(nil), // 0: Foo
}
var file_messages_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_messages_proto_init() }
func file_messages_proto_init() {
if File_messages_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_messages_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Foo); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_messages_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_messages_proto_goTypes,
DependencyIndexes: file_messages_proto_depIdxs,
MessageInfos: file_messages_proto_msgTypes,
}.Build()
File_messages_proto = out.File
file_messages_proto_rawDesc = nil
file_messages_proto_goTypes = nil
file_messages_proto_depIdxs = nil
}

8
example/messages.proto

@ -0,0 +1,8 @@
syntax = "proto3";
option go_package = ".;main";
message Foo {
int64 id = 1;
string message = 2;
}

11
go.mod

@ -0,0 +1,11 @@
module code.hollensbe.org/erikh/natsrouter
go 1.14
require (
github.com/golang/protobuf v1.4.0
github.com/nats-io/nats.go v1.9.2
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 // indirect
google.golang.org/protobuf v1.22.0
)

38
go.sum

@ -0,0 +1,38 @@
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI=
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
github.com/nats-io/nats.go v1.9.2 h1:oDeERm3NcZVrPpdR/JpGdWHMv3oJ8yY30YwxKq+DU2s=
github.com/nats-io/nats.go v1.9.2/go.mod h1:AjGArbfyR50+afOUotNX2Xs5SYHf+CoOa5HH1eEl2HE=
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
github.com/nats-io/nkeys v0.1.4 h1:aEsHIssIk6ETN5m2/MD8Y4B2X7FfXrBAUdkyRvbVYzA=
github.com/nats-io/nkeys v0.1.4/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79 h1:IaQbIIB2X/Mp/DKctl6ROxz1KyMlKp4uyvL6+kQ7C88=
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=

113
router.go

@ -0,0 +1,113 @@
package natsrouter
import (
"context"
"log"
"github.com/nats-io/nats.go"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)
//go:generate protoc --proto_path=.:$GOPATH/src --go_out=. router.proto
// Router is the router object. Strings are matched literally; pass data
// through the structs. There is no HTTP style route.
type Router map[string]Handler
// Handler encapsulates a type and HandlerFunc. The InputTypeFunc must return
// interface proto.Message; the encapsulated data will be unmarshalled to it.
type Handler struct {
Func HandlerFunc
InputTypeFunc func() proto.Message
}
// HandlerFunc receives a proto.Message and processes it. It also recieves a
// context which will be cancelled if the service closes while the request is
// in flight.
type HandlerFunc func(context context.Context, msg proto.Message)
// NewRouter creates a new router for use.
func NewRouter() Router {
return Router{}
}
// HandleFunc handles a route with a HandlerFunc. Handler routes are literal
// strings and will not match wildcards. Routes will be overwritten if this is
// called twice with the same string route.
func (r Router) HandleFunc(route string, h Handler) Router {
r[route] = h
return r
}
// Handle takes a nats subscription and reads it until the context or the
// connection is closed. Each message is delivered to a goroutine for
// processing.
//
// You are responsible for maintaining the subscription.
func (r Router) Handle(ctx context.Context, sub *nats.Subscription) error {
for {
msg, err := sub.NextMsgWithContext(ctx)
if err != nil {
return err
}
m := &Message{}
if err := proto.Unmarshal(msg.Data, m); err != nil {
return errors.Wrap(err, "error unmarshalling routing envelope from NATS")
}
handler, ok := r[m.Route]
if !ok {
log.Printf("could not locate route %v", m.Route)
continue
}
input := handler.InputTypeFunc()
if err := proto.Unmarshal(m.Data, input); err != nil {
return errors.Wrapf(err, "could not unamrshal payload to protobuf type: %T", input)
}
go handler.Func(ctx, input)
}
}
// Publisher publishes to a route
type Publisher struct {
conn *nats.Conn
r Router
subject string
}
// GetPublisher returns a publisher
func (r Router) GetPublisher(conn *nats.Conn, subject string) *Publisher {
return &Publisher{
conn: conn,
r: r,
subject: subject,
}
}
// Publish publishes a message to the route
func (p *Publisher) Publish(route string, msg proto.Message) error {
if _, ok := p.r[route]; !ok {
return errors.Errorf("handler does not exist for route %q", route)
}
bytes, err := proto.Marshal(msg)
if err != nil {
return errors.Wrap(err, "could not marshal payload")
}
m := &Message{
Route: route,
Data: bytes,
}
marshalled, err := proto.Marshal(m)
if err != nil {
return errors.Wrap(err, "could not marshal envelope")
}
return p.conn.Publish(p.subject, marshalled)
}

155
router.pb.go

@ -0,0 +1,155 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.22.0
// protoc v3.11.4
// source: router.proto
package natsrouter
import (
proto "github.com/golang/protobuf/proto"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type Message struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Route string `protobuf:"bytes,1,opt,name=route,proto3" json:"route,omitempty"`
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *Message) Reset() {
*x = Message{}
if protoimpl.UnsafeEnabled {
mi := &file_router_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Message) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Message) ProtoMessage() {}
func (x *Message) ProtoReflect() protoreflect.Message {
mi := &file_router_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Message.ProtoReflect.Descriptor instead.
func (*Message) Descriptor() ([]byte, []int) {
return file_router_proto_rawDescGZIP(), []int{0}
}
func (x *Message) GetRoute() string {
if x != nil {
return x.Route
}
return ""
}
func (x *Message) GetData() []byte {
if x != nil {
return x.Data
}
return nil
}
var File_router_proto protoreflect.FileDescriptor
var file_router_proto_rawDesc = []byte{
0x0a, 0x0c, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x33,
0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75,
0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x12,
0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64,
0x61, 0x74, 0x61, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x3b, 0x6e, 0x61, 0x74, 0x73, 0x72, 0x6f, 0x75,
0x74, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_router_proto_rawDescOnce sync.Once
file_router_proto_rawDescData = file_router_proto_rawDesc
)
func file_router_proto_rawDescGZIP() []byte {
file_router_proto_rawDescOnce.Do(func() {
file_router_proto_rawDescData = protoimpl.X.CompressGZIP(file_router_proto_rawDescData)
})
return file_router_proto_rawDescData
}
var file_router_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_router_proto_goTypes = []interface{}{
(*Message)(nil), // 0: Message
}
var file_router_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_router_proto_init() }
func file_router_proto_init() {
if File_router_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_router_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Message); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_router_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_router_proto_goTypes,
DependencyIndexes: file_router_proto_depIdxs,
MessageInfos: file_router_proto_msgTypes,
}.Build()
File_router_proto = out.File
file_router_proto_rawDesc = nil
file_router_proto_goTypes = nil
file_router_proto_depIdxs = nil
}

8
router.proto

@ -0,0 +1,8 @@
syntax = "proto3";
option go_package = ".;natsrouter";
message Message {
string route = 1;
bytes data = 2;
}
Loading…
Cancel
Save