Browse Source

Hello, world. Only the server is working. Well, maybe it is. There isn't a client to check it with yet,.

Pat Lathem 2 years ago
commit
22f5b9abf3
4 changed files with 199 additions and 0 deletions
  1. BIN
      proto/.hello.pb.go.swp
  2. 149 0
      proto/hello.pb.go
  3. 14 0
      proto/hello.proto
  4. 36 0
      server/main.go

BIN
proto/.hello.pb.go.swp


+ 149 - 0
proto/hello.pb.go

@@ -0,0 +1,149 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// source: hello.proto
+
+/*
+Package helloworld is a generated protocol buffer package.
+
+It is generated from these files:
+	hello.proto
+
+It has these top-level messages:
+	HelloResponse
+	HelloRequest
+*/
+package helloworld
+
+import proto "github.com/golang/protobuf/proto"
+import fmt "fmt"
+import math "math"
+
+import (
+	context "golang.org/x/net/context"
+	grpc "google.golang.org/grpc"
+)
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ = proto.Marshal
+var _ = fmt.Errorf
+var _ = math.Inf
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the proto package it is being compiled against.
+// A compilation error at this line likely means your copy of the
+// proto package needs to be updated.
+const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
+
+type HelloResponse struct {
+	Response string `protobuf:"bytes,1,opt,name=response" json:"response,omitempty"`
+}
+
+func (m *HelloResponse) Reset()                    { *m = HelloResponse{} }
+func (m *HelloResponse) String() string            { return proto.CompactTextString(m) }
+func (*HelloResponse) ProtoMessage()               {}
+func (*HelloResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
+
+func (m *HelloResponse) GetResponse() string {
+	if m != nil {
+		return m.Response
+	}
+	return ""
+}
+
+type HelloRequest struct {
+}
+
+func (m *HelloRequest) Reset()                    { *m = HelloRequest{} }
+func (m *HelloRequest) String() string            { return proto.CompactTextString(m) }
+func (*HelloRequest) ProtoMessage()               {}
+func (*HelloRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
+
+func init() {
+	proto.RegisterType((*HelloResponse)(nil), "helloworld.HelloResponse")
+	proto.RegisterType((*HelloRequest)(nil), "helloworld.HelloRequest")
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ context.Context
+var _ grpc.ClientConn
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+const _ = grpc.SupportPackageIsVersion4
+
+// Client API for Hello service
+
+type HelloClient interface {
+	World(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error)
+}
+
+type helloClient struct {
+	cc *grpc.ClientConn
+}
+
+func NewHelloClient(cc *grpc.ClientConn) HelloClient {
+	return &helloClient{cc}
+}
+
+func (c *helloClient) World(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) {
+	out := new(HelloResponse)
+	err := grpc.Invoke(ctx, "/helloworld.Hello/World", in, out, c.cc, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// Server API for Hello service
+
+type HelloServer interface {
+	World(context.Context, *HelloRequest) (*HelloResponse, error)
+}
+
+func RegisterHelloServer(s *grpc.Server, srv HelloServer) {
+	s.RegisterService(&_Hello_serviceDesc, srv)
+}
+
+func _Hello_World_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(HelloRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(HelloServer).World(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/helloworld.Hello/World",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(HelloServer).World(ctx, req.(*HelloRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+var _Hello_serviceDesc = grpc.ServiceDesc{
+	ServiceName: "helloworld.Hello",
+	HandlerType: (*HelloServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "World",
+			Handler:    _Hello_World_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "hello.proto",
+}
+
+func init() { proto.RegisterFile("hello.proto", fileDescriptor0) }
+
+var fileDescriptor0 = []byte{
+	// 121 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0x48, 0xcd, 0xc9,
+	0xc9, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x02, 0x73, 0xca, 0xf3, 0x8b, 0x72, 0x52,
+	0x94, 0xb4, 0xb9, 0x78, 0x3d, 0x40, 0xbc, 0xa0, 0xd4, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x21,
+	0x29, 0x2e, 0x8e, 0x22, 0x28, 0x5b, 0x82, 0x51, 0x81, 0x51, 0x83, 0x33, 0x08, 0xce, 0x57, 0xe2,
+	0xe3, 0xe2, 0x81, 0x2a, 0x2e, 0x2c, 0x4d, 0x2d, 0x2e, 0x31, 0x72, 0xe7, 0x62, 0x05, 0xf3, 0x85,
+	0xec, 0xb8, 0x58, 0xc3, 0x41, 0xc6, 0x09, 0x49, 0xe8, 0x21, 0xcc, 0xd6, 0x43, 0x56, 0x2b, 0x25,
+	0x89, 0x45, 0x06, 0x6a, 0x2c, 0x43, 0x12, 0x1b, 0xd8, 0x61, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff,
+	0xff, 0x10, 0x4b, 0x9a, 0x4a, 0xa7, 0x00, 0x00, 0x00,
+}

+ 14 - 0
proto/hello.proto

@@ -0,0 +1,14 @@
+syntax = "proto3";
+package helloworld;
+
+service Hello {
+  rpc World(HelloRequest) returns (HelloResponse) {}
+}
+
+message HelloResponse {
+  string response = 1;
+}
+
+message HelloRequest {}
+
+

+ 36 - 0
server/main.go

@@ -0,0 +1,36 @@
+package main
+
+// Allows `go generate` to build the go source from the proto definition
+//go:generate protoc -I ../proto --go_out=plugins=grpc:../proto ../proto/hello.proto
+
+import (
+	"log"
+	"net"
+
+	"golang.org/x/net/context"
+	"google.golang.org/grpc"
+
+	pb "gitrex.com/pat/helloworld/proto"
+)
+
+const (
+	port = ":50051"
+)
+
+// ?
+type server struct {
+}
+
+func (s *server) World(ctx context.Context, in *pb.HelloRequest) (*pb.HelloResponse, error) {
+	return &pb.HelloResponse{Response: "Greetings"}, nil
+}
+
+func main() {
+	lis, err := net.Listen("tcp", port)
+	if err != nil {
+		log.Fatalf("failed to listen: %v", err)
+	}
+	s := grpc.NewServer()
+	pb.RegisterHelloServer(s, &server{})
+	s.Serve(lis)
+}