mirror of
https://github.com/go-micro/go-micro.git
synced 2025-12-05 21:56:14 +02:00
Add examples
This commit is contained in:
27
examples/function/main.go
Normal file
27
examples/function/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
proto "github.com/micro/examples/function/proto"
|
||||
"github.com/micro/go-micro/v2"
|
||||
)
|
||||
|
||||
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() {
|
||||
fnc := micro.NewFunction(
|
||||
micro.Name("greeter"),
|
||||
)
|
||||
|
||||
fnc.Init()
|
||||
|
||||
fnc.Handle(new(Greeter))
|
||||
|
||||
fnc.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user