Skip to content

Commit 4ead4ff

Browse files
authored
Update README.md (#2750)
1 parent 200a3cb commit 4ead4ff

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

README.md

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ To make use of Go Micro import it
5151
import "go-micro.dev/v5"
5252
```
5353

54-
Define a handler (protobuf is supported via [protoc-gen-micro](https://github.com/micro/go-micro/tree/master/cmd/protoc-gen-micro))
54+
Create a service and register a handler
5555

5656
```golang
57+
package main
58+
59+
import (
60+
"go-micro.dev/v5"
61+
)
62+
5763
type Request struct {
5864
Name string `json:"name"`
5965
}
@@ -62,35 +68,27 @@ type Response struct {
6268
Message string `json:"message"`
6369
}
6470

65-
type Helloworld struct{}
71+
type Say struct{}
6672

67-
func (h *Helloworld) Greeting(ctx context.Context, req *Request, rsp *Response) error {
73+
func (h *Say) Hello(ctx context.Context, req *Request, rsp *Response) error {
6874
rsp.Message = "Hello " + req.Name
6975
return nil
7076
}
71-
```
72-
73-
Create, initialise and run the service
7477

75-
```golang
76-
// create a new service
78+
// create the service
7779
service := micro.New("helloworld")
7880

7981
// register handler
80-
service.Handle(new(Helloworld))
82+
service.Handle(new(Say))
8183

82-
// initialise flags
83-
service.Init()
84-
85-
// start the service
84+
// run the service
8685
service.Run()
8786
```
8887

8988
Optionally set fixed address
9089

9190
```golang
9291
service := micro.NewService(
93-
// set address
9492
micro.Address(":8080"),
9593
)
9694
```
@@ -100,11 +98,35 @@ Call it via curl
10098
```
10199
curl -XPOST \
102100
-H 'Content-Type: application/json' \
103-
-H 'Micro-Endpoint: Helloworld.Greeting' \
101+
-H 'Micro-Endpoint: Say.Hello' \
104102
-d '{"name": "alice"}' \
105103
http://localhost:8080
106104
```
107105

106+
## Micro
107+
108+
Use the [Micro](https://github.com/micro/micro) cli to call it
109+
110+
```
111+
micro call helloworld Say.Hello '{"name": "Asim"}'
112+
```
113+
114+
Run the micro api and call it via the http
115+
116+
```
117+
micro api
118+
```
119+
120+
Call it via http://localhost:8080/
121+
122+
```
123+
curl -d '{"name": "Asim"}' https://localhost:8080/helloworld/Say/Hello
124+
```
125+
126+
## Protobuf
127+
128+
Protobuf is supported via [protoc-gen-micro](https://github.com/micro/go-micro/tree/master/cmd/protoc-gen-micro)
129+
108130
## Plugins
109131

110132
See [Plugins](https://github.com/micro/plugins) for implementations of the various core interfaces.

0 commit comments

Comments
 (0)