This commit is contained in:
Asim Aslam
2020-10-02 11:13:01 +01:00
commit 61fe9c169b
62 changed files with 4428 additions and 0 deletions

2
helloworld/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
helloworld
helloworld-srv

3
helloworld/Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM alpine
ADD helloworld-srv /helloworld-srv
ENTRYPOINT [ "/helloworld-srv" ]

20
helloworld/Makefile Normal file
View File

@@ -0,0 +1,20 @@
GOPATH:=$(shell go env GOPATH)
.PHONY: proto
proto:
protoc --proto_path=${GOPATH}/src:. --micro_out=. --go_out=. proto/helloworld/helloworld.proto
.PHONY: build
build: proto
go build -o helloworld-srv *.go
.PHONY: test
test:
go test -v ./... -cover
.PHONY: docker
docker:
docker build . -t helloworld-srv:latest

20
helloworld/README.md Normal file
View File

@@ -0,0 +1,20 @@
# Helloworld Service
This is the Helloworld service
## Overview
An example of how to write a simple helloworld service. This can also be generated using `micro new helloworld`.
## Usage
```
# run the server
micro server
# run the service
micro run github.com/micro/services/helloworld
## call the service
micro call helloworld Helloworld.Call '{"name": "Alice"}'
```

3
helloworld/generate.go Normal file
View File

@@ -0,0 +1,3 @@
package main
//go:generate make proto

View File

@@ -0,0 +1,17 @@
package handler
import (
"context"
"github.com/micro/micro/v3/service/logger"
helloworld "github.com/micro/services/helloworld/proto"
)
type Helloworld struct{}
// Call is a single request handler called via client.Call or the generated client code
func (e *Helloworld) Call(ctx context.Context, req *helloworld.Request, rsp *helloworld.Response) error {
logger.Info("Received Helloworld.Call request")
rsp.Msg = "Hello " + req.Name
return nil
}

22
helloworld/main.go Normal file
View File

@@ -0,0 +1,22 @@
package main
import (
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/logger"
"github.com/micro/services/helloworld/handler"
)
func main() {
// Create service
srv := service.New(
service.Name("helloworld"),
)
// Register Handler
srv.Handle(new(handler.Helloworld))
// Run the service
if err := srv.Run(); err != nil {
logger.Fatal(err)
}
}

View File

@@ -0,0 +1,119 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: helloworld/proto/helloworld.proto
package helloworld
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
// 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.ProtoPackageIsVersion3 // please upgrade the proto package
type Request struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
func (*Request) Descriptor() ([]byte, []int) {
return fileDescriptor_641cff7980a2aacd, []int{0}
}
func (m *Request) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Request.Unmarshal(m, b)
}
func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Request.Marshal(b, m, deterministic)
}
func (m *Request) XXX_Merge(src proto.Message) {
xxx_messageInfo_Request.Merge(m, src)
}
func (m *Request) XXX_Size() int {
return xxx_messageInfo_Request.Size(m)
}
func (m *Request) XXX_DiscardUnknown() {
xxx_messageInfo_Request.DiscardUnknown(m)
}
var xxx_messageInfo_Request proto.InternalMessageInfo
func (m *Request) GetName() string {
if m != nil {
return m.Name
}
return ""
}
type Response struct {
Msg string `protobuf:"bytes,1,opt,name=msg,proto3" json:"msg,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (*Response) Descriptor() ([]byte, []int) {
return fileDescriptor_641cff7980a2aacd, []int{1}
}
func (m *Response) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Response.Unmarshal(m, b)
}
func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Response.Marshal(b, m, deterministic)
}
func (m *Response) XXX_Merge(src proto.Message) {
xxx_messageInfo_Response.Merge(m, src)
}
func (m *Response) XXX_Size() int {
return xxx_messageInfo_Response.Size(m)
}
func (m *Response) XXX_DiscardUnknown() {
xxx_messageInfo_Response.DiscardUnknown(m)
}
var xxx_messageInfo_Response proto.InternalMessageInfo
func (m *Response) GetMsg() string {
if m != nil {
return m.Msg
}
return ""
}
func init() {
proto.RegisterType((*Request)(nil), "helloworld.Request")
proto.RegisterType((*Response)(nil), "helloworld.Response")
}
func init() { proto.RegisterFile("helloworld/proto/helloworld.proto", fileDescriptor_641cff7980a2aacd) }
var fileDescriptor_641cff7980a2aacd = []byte{
// 138 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0xcc, 0x48, 0xcd, 0xc9,
0xc9, 0x2f, 0xcf, 0x2f, 0xca, 0x49, 0xd1, 0x2f, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x47, 0x08, 0xe8,
0x81, 0x05, 0x84, 0xb8, 0x10, 0x22, 0x4a, 0xb2, 0x5c, 0xec, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5,
0x25, 0x42, 0x42, 0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41,
0x60, 0xb6, 0x92, 0x0c, 0x17, 0x47, 0x50, 0x6a, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0x90, 0x00,
0x17, 0x73, 0x6e, 0x71, 0x3a, 0x54, 0x1a, 0xc4, 0x34, 0x72, 0xe4, 0xe2, 0xf2, 0x80, 0x1b, 0x25,
0x64, 0xcc, 0xc5, 0xe2, 0x9c, 0x98, 0x93, 0x23, 0x24, 0xac, 0x87, 0x64, 0x23, 0xd4, 0x70, 0x29,
0x11, 0x54, 0x41, 0x88, 0x91, 0x4a, 0x0c, 0x49, 0x6c, 0x60, 0x27, 0x19, 0x03, 0x02, 0x00, 0x00,
0xff, 0xff, 0x72, 0xbc, 0x74, 0x44, 0xb7, 0x00, 0x00, 0x00,
}

View File

@@ -0,0 +1,93 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: helloworld/proto/helloworld.proto
package helloworld
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
api "github.com/micro/go-micro/v3/api"
client "github.com/micro/go-micro/v3/client"
server "github.com/micro/go-micro/v3/server"
)
// 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.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for Helloworld service
func NewHelloworldEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Helloworld service
type HelloworldService interface {
Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error)
}
type helloworldService struct {
c client.Client
name string
}
func NewHelloworldService(name string, c client.Client) HelloworldService {
return &helloworldService{
c: c,
name: name,
}
}
func (c *helloworldService) Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) {
req := c.c.NewRequest(c.name, "Helloworld.Call", in)
out := new(Response)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Helloworld service
type HelloworldHandler interface {
Call(context.Context, *Request, *Response) error
}
func RegisterHelloworldHandler(s server.Server, hdlr HelloworldHandler, opts ...server.HandlerOption) error {
type helloworld interface {
Call(ctx context.Context, in *Request, out *Response) error
}
type Helloworld struct {
helloworld
}
h := &helloworldHandler{hdlr}
return s.Handle(s.NewHandler(&Helloworld{h}, opts...))
}
type helloworldHandler struct {
HelloworldHandler
}
func (h *helloworldHandler) Call(ctx context.Context, in *Request, out *Response) error {
return h.HelloworldHandler.Call(ctx, in, out)
}

View File

@@ -0,0 +1,15 @@
syntax = "proto3";
package helloworld;
service Helloworld {
rpc Call(Request) returns (Response) {}
}
message Request {
string name = 1;
}
message Response {
string msg = 1;
}