Cleanup and move template

This commit is contained in:
Asim
2015-05-25 18:16:42 +01:00
parent 94dee7a459
commit 5516f7ea1f
14 changed files with 78 additions and 145 deletions

View File

@@ -6,14 +6,15 @@ import (
"github.com/myodc/go-micro/client"
"github.com/myodc/go-micro/cmd"
c "github.com/myodc/go-micro/context"
example "github.com/myodc/go-micro/template/proto/example"
example "github.com/myodc/go-micro/examples/server/proto/example"
"golang.org/x/net/context"
)
func main() {
cmd.Init()
// Create new request to service go.micro.service.go-template, method Example.Call
req := client.NewRequest("go.micro.service.template", "Example.Call", &example.Request{
// Create new request to service go.micro.srv.example, method Example.Call
req := client.NewRequest("go.micro.srv.example", "Example.Call", &example.Request{
Name: "John",
})

View File

@@ -1,24 +0,0 @@
package main
import (
"fmt"
h "github.com/grpc/grpc-common/go/helloworld"
"github.com/myodc/go-micro/client"
"golang.org/x/net/context"
)
// run github.com/grpc/grpc-common/go/greeter_server/main.go
func main() {
req := client.NewRpcRequest("helloworld.Greeter", "helloworld.Greeter/SayHello", &h.HelloRequest{
Name: "John",
}, "application/grpc")
rsp := &h.HelloReply{}
err := client.CallRemote(context.Background(), "localhost:50051", req, rsp)
if err != nil {
fmt.Println(err)
}
fmt.Println(rsp.Message)
}

View File

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

27
examples/server/README.md Normal file
View File

@@ -0,0 +1,27 @@
# Example 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 server/main.go
I0525 18:06:14.471489 83304 server.go:117] Starting server go.micro.srv.example id go.micro.srv.example-59b6e0ab-0300-11e5-b696-68a86d0d36b6
I0525 18:06:14.474960 83304 rpc_server.go:126] Listening on [::]:62216
I0525 18:06:14.474997 83304 server.go:99] Registering node: go.micro.srv.example-59b6e0ab-0300-11e5-b696-68a86d0d36b6
```
Test Service
```
$ go run client/main.go
go.micro.srv.example-59b6e0ab-0300-11e5-b696-68a86d0d36b6: Hello John
```

View File

@@ -0,0 +1,19 @@
package handler
import (
log "github.com/golang/glog"
c "github.com/myodc/go-micro/context"
example "github.com/myodc/go-micro/examples/server/proto/example"
"github.com/myodc/go-micro/server"
"golang.org/x/net/context"
)
type Example struct{}
func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
md, _ := c.GetMetaData(ctx)
log.Info("Received Example.Call request with metadata: %v", md)
rsp.Msg = server.Id + ": Hello " + req.Name
return nil
}

30
examples/server/main.go Normal file
View File

@@ -0,0 +1,30 @@
package main
import (
log "github.com/golang/glog"
"github.com/myodc/go-micro/cmd"
"github.com/myodc/go-micro/examples/server/handler"
"github.com/myodc/go-micro/server"
)
func main() {
// optionally setup command line usage
cmd.Init()
server.Name = "go.micro.srv.example"
// Initialise Server
server.Init()
// Register Handlers
server.Register(
server.NewReceiver(
new(handler.Example),
),
)
// Run server
if err := server.Run(); err != nil {
log.Fatal(err)
}
}

View File

@@ -0,0 +1,39 @@
// Code generated by protoc-gen-go.
// source: go-micro/examples/server/proto/example/example.proto
// DO NOT EDIT!
/*
Package example is a generated protocol buffer package.
It is generated from these files:
go-micro/examples/server/proto/example/example.proto
It has these top-level messages:
Request
Response
*/
package example
import proto "github.com/golang/protobuf/proto"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
type Request struct {
Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
}
func (m *Request) Reset() { *m = Request{} }
func (m *Request) String() string { return proto.CompactTextString(m) }
func (*Request) ProtoMessage() {}
type Response struct {
Msg string `protobuf:"bytes,1,opt,name=msg" json:"msg,omitempty"`
}
func (m *Response) Reset() { *m = Response{} }
func (m *Response) String() string { return proto.CompactTextString(m) }
func (*Response) ProtoMessage() {}
func init() {
}

View File

@@ -0,0 +1,9 @@
syntax = "proto3";
message Request {
string name = 1;
}
message Response {
string msg = 1;
}