This commit is contained in:
Asim
2015-01-13 23:31:27 +00:00
commit 8e55cde513
43 changed files with 1639 additions and 0 deletions

3
template/Dockerfile Normal file
View File

@@ -0,0 +1,3 @@
FROM scratch
ADD template /
ENTRYPOINT [ "/template" ]

30
template/README.md Normal file
View File

@@ -0,0 +1,30 @@
# Template Service
An example Go service running with go-micro
### Prerequisites
Install Consul
[https://www.consul.io/intro/getting-started/install.html](https://www.consul.io/intro/getting-started/install.html)
Run Consul
```
$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul
```
Run Service
```
$ go run main.go
1416690099281057746 [Debug] Rpc handler /_rpc
1416690099281092588 [Debug] Starting server go.micro.service.go-template id go.micro.service.go-template-c0bfcb44-728a-11e4-b099-68a86d0d36b6
1416690099281192941 [Debug] Listening on [::]:58264
1416690099281215346 [Debug] Registering go.micro.service.go-template-c0bfcb44-728a-11e4-b099-68a86d0d36b6
```
Test Service
```
$ go run go-micro/examples/service_client.go
go.micro.service.go-template-c0bfcb44-728a-11e4-b099-68a86d0d36b6: Hello John
```

View File

@@ -0,0 +1,20 @@
package handler
import (
"code.google.com/p/go.net/context"
"code.google.com/p/goprotobuf/proto"
"github.com/asim/go-micro/server"
example "github.com/asim/go-micro/template/proto/example"
log "github.com/cihub/seelog"
)
type Example struct{}
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
log.Debug("Received Example.Call request")
rsp.Msg = proto.String(server.Id + ": Hello " + req.GetName())
return nil
}

28
template/main.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"log"
"github.com/asim/go-micro/server"
"github.com/asim/go-micro/template/handler"
)
func main() {
server.Name = "go.micro.service.template"
// Initialise Server
server.Init()
// Register Handlers
server.Register(
server.NewReceiver(
new(handler.Example),
),
)
// Run server
if err := server.Run(); err != nil {
log.Fatal(err)
}
}

21
template/pod.json Normal file
View File

@@ -0,0 +1,21 @@
{
"kind": "Pod",
"apiVersion": "v1beta1",
"id": "template-service",
"desiredState": {
"manifest": {
"version": "v1beta1",
"id": "template-service",
"containers": [{
"name": "template-service",
"image": "chuhnk/go-template",
"ports": [{"name": "template-service", "containerPort": 8080}],
"command": ["--registry=kubernetes", "--bind_address=:8080"]
}],
}
},
"labels": {
"name": "go.micro.service.template",
}
}

View File

@@ -0,0 +1,57 @@
// Code generated by protoc-gen-gogo.
// source: asim/go-micro/template/proto/example/example.proto
// DO NOT EDIT!
/*
Package go_micro_service_template_example is a generated protocol buffer package.
It is generated from these files:
asim/go-micro/template/proto/example/example.proto
It has these top-level messages:
Request
Response
*/
package go_micro_service_template_example
import proto "code.google.com/p/gogoprotobuf/proto"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = math.Inf
type Request struct {
Name *string `protobuf:"bytes,1,req,name=name" json:"name,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
func (m *Request) GetName() string {
if m != nil && m.Name != nil {
return *m.Name
}
return ""
}
type Response struct {
Msg *string `protobuf:"bytes,1,req,name=msg" json:"msg,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func (m *Response) GetMsg() string {
if m != nil && m.Msg != nil {
return *m.Msg
}
return ""
}
func init() {
}

View File

@@ -0,0 +1,9 @@
package go.micro.service.template.example;
message Request {
required string name = 1;
}
message Response {
required string msg = 1;
}

9
template/service.json Normal file
View File

@@ -0,0 +1,9 @@
{
"id": "template-service",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 9091,
"containerPort": 8080,
"selector": { "name": "go.micro.service.template" },
"labels": { "name": "go.micro.service.template" }
}