update readme
This commit is contained in:
parent
e870bffef2
commit
1932bc805b
47
README.md
47
README.md
@ -20,14 +20,15 @@ Go Micro abstracts way the details of distributed systems. Here are the main fea
|
|||||||
- **Message Encoding** - Micro services can encode requests in a number of encoding formats and seamlessly decode based on the Content-Type header.
|
- **Message Encoding** - Micro services can encode requests in a number of encoding formats and seamlessly decode based on the Content-Type header.
|
||||||
- **RPC Client/Server** - The client and server leverage the above features and provide a clean simple interface for building microservices.
|
- **RPC Client/Server** - The client and server leverage the above features and provide a clean simple interface for building microservices.
|
||||||
|
|
||||||
|
Go Micro supports both the Service and Function programming models. Read on to learn more.
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
For more detailed information on the architecture, installation and use of go-micro checkout the [docs](https://micro.mu/docs).
|
For more detailed information on the architecture, installation and use of go-micro checkout the [docs](https://micro.mu/docs).
|
||||||
|
|
||||||
## Learn By Example
|
## Learn By Example
|
||||||
|
|
||||||
An example service can be found in [**examples/service**](https://github.com/micro/examples/tree/master/service). The [**examples**](https://github.com/micro/examples) directory contains many more examples for using things such as middleware/wrappers, selector filters, pub/sub and code generation.
|
An example service can be found in [**examples/service**](https://github.com/micro/examples/tree/master/service) and function in [**examples/function**](https://github.com/micro/examples/tree/master/function). The [**examples**](https://github.com/micro/examples) directory contains many more examples for using things such as middleware/wrappers, selector filters, pub/sub and code generation.
|
||||||
|
|
||||||
For the complete greeter example look at [**examples/greeter**](https://github.com/micro/examples/tree/master/greeter). Other examples can be found throughout the GitHub repository.
|
For the complete greeter example look at [**examples/greeter**](https://github.com/micro/examples/tree/master/greeter). Other examples can be found throughout the GitHub repository.
|
||||||
|
|
||||||
Check out the blog post to learn how to write go-micro services [https://micro.mu/blog/2016/03/28/go-micro.html](https://micro.mu/blog/2016/03/28/go-micro.html) or watch the talk from the [Golang UK Conf 2016](https://www.youtube.com/watch?v=xspaDovwk34).
|
Check out the blog post to learn how to write go-micro services [https://micro.mu/blog/2016/03/28/go-micro.html](https://micro.mu/blog/2016/03/28/go-micro.html) or watch the talk from the [Golang UK Conf 2016](https://www.youtube.com/watch?v=xspaDovwk34).
|
||||||
@ -228,6 +229,48 @@ go run client.go
|
|||||||
Hello John
|
Hello John
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Writing a Function
|
||||||
|
|
||||||
|
Go Micro includes the Function programming model. This is the notion of a one time executing Service which operates much like a service except exiting
|
||||||
|
after completing a request. A function is defined much like a service and called in exactly the same way.
|
||||||
|
|
||||||
|
### Defining a Function
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
proto "github.com/micro/examples/function/proto"
|
||||||
|
"github.com/micro/go-micro"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Greeter struct{}
|
||||||
|
|
||||||
|
func (g *Greeter) Hello(ctx context.Context, req *proto.HelloRequest, rsp *proto.HelloResponse) error {
|
||||||
|
rsp.Greeting = "Hello " + req.Name
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// create a new function
|
||||||
|
fnc := micro.NewFunction(
|
||||||
|
micro.Name("go.micro.fnc.greeter"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// init the command line
|
||||||
|
fnc.Init()
|
||||||
|
|
||||||
|
// register a handler
|
||||||
|
fnc.Handle(new(Greeter))
|
||||||
|
|
||||||
|
// run the function
|
||||||
|
fnc.Run()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
It's that simple.
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user