toldata

package module
v0.0.0-...-634d6dc Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

Toldata

Protobuf for Nats.io

This Go module simplifies how you use protobuf with Nats.io:

  1. Provide proto files
  2. Provide Go implementations
  3. Bind the implementation on the server side
  4. Make a call from the clients
Example

Proto:

message TestARequest {
    string input = 1; 
}

message TestAResponse {
    string output = 1;
}

service TestService {
    rpc GetTestA(TestARequest) returns (TestAResponse) {}
}

Implementation:

func (b *TestServiceProtonats) GetTestA(ctx context.Context, req *TestARequest) (*TestAResponse, error) {
	...
    //some business
    ...
    if err != nil {
		return nil, err
	}

	result := &TestAResponse{
		Output: "OK",
	}
	return result, nil
}

Server side:

Generate the server code from the proto file with --toldata_out= argument to protoc-gen-go, then:

    service := &TestServiceProtonats{}
    ...
    ctx, cancel := context.WithCancel(context.Background())
	bus, err := NewBus(ctx, ServiceConfiguration{URL: natsURL, ID: "bus1"})
	defer bus.Close()
	svr := NewTestServiceProtonatsServer(bus, d)
	chan, err = svr.SubscribeTestService()

    ...
	cancel() // cancel services
	...
	<-chan  // wait and unsubscribe 

Client side:

Generate the client code from the proto file with --toldata_out= argument to protoc-gen-go, then:

    var client *Bus
	client, err = NewBus(ctx, ServiceConfiguration{URL: natsURL})
	
	defer client.Close()

	svc := NewTestServiceProtonatsClient(client)
	resp, err := svc.GetTestA(ctx, &TestARequest{Input: "OK"})

GRPC Gateway

A GRPC gateway listens GRPC requests and forward them to NATS. The gateway can be generated by generating code from the proto file with --toldata_out=gprc: argument to protoc-gen-go. See grpc_test.go file to check how toimplement the bridge.

License

This software is licensed under Apache 2 license.

(c) 2019 Citra Digital Lintas

Documentation

Index

Constants

View Source
const (
	RestTemplate = `` /* 2544-byte string literal not displayed */

	GRPCTemplate = `` /* 2450-byte string literal not displayed */

	RPCTemplate = `` /* 17307-byte string literal not displayed */

)

Variables

View Source
var (
	// optional string rest_mount = 99999;
	E_RestMount = &file_api_toldata_proto_extTypes[0]
)

Extension fields to descriptorpb.ServiceOptions.

View Source
var File_api_toldata_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Bus

type Bus struct {
	Connection    *nats.Conn
	Configuration ServiceConfiguration
	Context       context.Context
}

func NewBus

func NewBus(ctx context.Context, config ServiceConfiguration) (*Bus, error)

func (*Bus) Close

func (bus *Bus) Close()

func (*Bus) HandleError

func (bus *Bus) HandleError(replySubject string, err error)

type Empty

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

func (*Empty) Descriptor deprecated

func (*Empty) Descriptor() ([]byte, []int)

Deprecated: Use Empty.ProtoReflect.Descriptor instead.

func (*Empty) ProtoMessage

func (*Empty) ProtoMessage()

func (*Empty) ProtoReflect

func (x *Empty) ProtoReflect() protoreflect.Message

func (*Empty) Reset

func (x *Empty) Reset()

func (*Empty) String

func (x *Empty) String() string

type ErrorMessage

type ErrorMessage struct {
	ErrorMessage string `protobuf:"bytes,1,opt,name=error_message,json=error-message,proto3" json:"error_message,omitempty"`
	Timestamp    int64  `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	BusID        string `protobuf:"bytes,3,opt,name=busID,json=bus-id,proto3" json:"busID,omitempty"`
	// contains filtered or unexported fields
}

func (*ErrorMessage) Descriptor deprecated

func (*ErrorMessage) Descriptor() ([]byte, []int)

Deprecated: Use ErrorMessage.ProtoReflect.Descriptor instead.

func (*ErrorMessage) GetBusID

func (x *ErrorMessage) GetBusID() string

func (*ErrorMessage) GetErrorMessage

func (x *ErrorMessage) GetErrorMessage() string

func (*ErrorMessage) GetTimestamp

func (x *ErrorMessage) GetTimestamp() int64

func (*ErrorMessage) ProtoMessage

func (*ErrorMessage) ProtoMessage()

func (*ErrorMessage) ProtoReflect

func (x *ErrorMessage) ProtoReflect() protoreflect.Message

func (*ErrorMessage) Reset

func (x *ErrorMessage) Reset()

func (*ErrorMessage) String

func (x *ErrorMessage) String() string

type Generator

type Generator struct {
	File                *descriptor.FileDescriptorProto
	PathsSourceRelative bool
}

func (Generator) Generate

func (Generator) GenerateGRPC

func (g Generator) GenerateGRPC() (*plugin.CodeGeneratorResponse_File, error)

func (Generator) GenerateREST

func (g Generator) GenerateREST() (*plugin.CodeGeneratorResponse_File, error)

type ServiceConfiguration

type ServiceConfiguration struct {
	URL string
	ID  string
}

type StreamInfo

type StreamInfo struct {
	ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
	// contains filtered or unexported fields
}

func (*StreamInfo) Descriptor deprecated

func (*StreamInfo) Descriptor() ([]byte, []int)

Deprecated: Use StreamInfo.ProtoReflect.Descriptor instead.

func (*StreamInfo) GetID

func (x *StreamInfo) GetID() string

func (*StreamInfo) ProtoMessage

func (*StreamInfo) ProtoMessage()

func (*StreamInfo) ProtoReflect

func (x *StreamInfo) ProtoReflect() protoreflect.Message

func (*StreamInfo) Reset

func (x *StreamInfo) Reset()

func (*StreamInfo) String

func (x *StreamInfo) String() string

type ToldataHealthCheckInfo

type ToldataHealthCheckInfo struct {
	Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*ToldataHealthCheckInfo) Descriptor deprecated

func (*ToldataHealthCheckInfo) Descriptor() ([]byte, []int)

Deprecated: Use ToldataHealthCheckInfo.ProtoReflect.Descriptor instead.

func (*ToldataHealthCheckInfo) GetData

func (x *ToldataHealthCheckInfo) GetData() string

func (*ToldataHealthCheckInfo) ProtoMessage

func (*ToldataHealthCheckInfo) ProtoMessage()

func (*ToldataHealthCheckInfo) ProtoReflect

func (x *ToldataHealthCheckInfo) ProtoReflect() protoreflect.Message

func (*ToldataHealthCheckInfo) Reset

func (x *ToldataHealthCheckInfo) Reset()

func (*ToldataHealthCheckInfo) String

func (x *ToldataHealthCheckInfo) String() string

Directories

Path Synopsis
cmd
Code generated by github.com/darmawan01/toldata.
Code generated by github.com/darmawan01/toldata.

Jump to

Keyboard shortcuts

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