Skip to content

Commit 6574180

Browse files
committed
.
1 parent 26adf49 commit 6574180

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+8375
-101
lines changed

client/rpc_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ const (
3030
)
3131

3232
type rpcClient struct {
33-
seq uint64
33+
seq uint64
3434
opts Options
3535
once atomic.Value
3636
pool pool.Pool
37-
mu sync.RWMutex
37+
mu sync.RWMutex
3838
}
3939

4040
func newRPCClient(opt ...Option) Client {

cmd/README.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Micro
2+
3+
Go Micro Command Line
4+
5+
## Install the CLI
6+
7+
Install `micro` via `go install`
8+
9+
```
10+
go install go-micro.dev/v5/cmd/micro@latest
11+
```
12+
13+
Or via install script
14+
15+
16+
## Create a service
17+
18+
Create your service (all setup is now automatic!):
19+
20+
```
21+
micro new helloworld
22+
```
23+
24+
This will:
25+
- Create a new service in the `helloworld` directory
26+
- Automatically run `go mod tidy` and `make proto` for you
27+
- Show the updated project tree including generated files
28+
- Warn you if `protoc` is not installed, with install instructions
29+
30+
## Run the service
31+
32+
Run the service
33+
34+
```
35+
micro run
36+
```
37+
38+
List services to see it's running and registered itself
39+
40+
```
41+
micro services
42+
```
43+
44+
## Describe the service
45+
46+
Describe the service to see available endpoints
47+
48+
```
49+
micro describe helloworld
50+
```
51+
52+
Output
53+
54+
```
55+
{
56+
"name": "helloworld",
57+
"version": "latest",
58+
"metadata": null,
59+
"endpoints": [
60+
{
61+
"request": {
62+
"name": "Request",
63+
"type": "Request",
64+
"values": [
65+
{
66+
"name": "name",
67+
"type": "string",
68+
"values": null
69+
}
70+
]
71+
},
72+
"response": {
73+
"name": "Response",
74+
"type": "Response",
75+
"values": [
76+
{
77+
"name": "msg",
78+
"type": "string",
79+
"values": null
80+
}
81+
]
82+
},
83+
"metadata": {},
84+
"name": "Helloworld.Call"
85+
},
86+
{
87+
"request": {
88+
"name": "Context",
89+
"type": "Context",
90+
"values": null
91+
},
92+
"response": {
93+
"name": "Stream",
94+
"type": "Stream",
95+
"values": null
96+
},
97+
"metadata": {
98+
"stream": "true"
99+
},
100+
"name": "Helloworld.Stream"
101+
}
102+
],
103+
"nodes": [
104+
{
105+
"metadata": {
106+
"broker": "http",
107+
"protocol": "mucp",
108+
"registry": "mdns",
109+
"server": "mucp",
110+
"transport": "http"
111+
},
112+
"id": "helloworld-31e55be7-ac83-4810-89c8-a6192fb3ae83",
113+
"address": "127.0.0.1:39963"
114+
}
115+
]
116+
}
117+
```
118+
119+
## Call the service
120+
121+
Call via RPC endpoint
122+
123+
```
124+
micro call helloworld Helloworld.Call '{"name": "Asim"}'
125+
```
126+
127+
## Create a client
128+
129+
Create a client to call the service
130+
131+
```go
132+
package main
133+
134+
import (
135+
"context"
136+
"fmt"
137+
138+
"go-micro.dev/v5"
139+
)
140+
141+
type Request struct {
142+
Name string
143+
}
144+
145+
type Response struct {
146+
Message string
147+
}
148+
149+
func main() {
150+
client := micro.New("helloworld").Client()
151+
152+
req := client.NewRequest("helloworld", "Helloworld.Call", &Request{Name: "John"})
153+
154+
var rsp Response
155+
156+
err := client.Call(context.TODO(), req, &rsp)
157+
if err != nil {
158+
fmt.Println(err)
159+
return
160+
}
161+
162+
fmt.Println(rsp.Message)
163+
}
164+
```
165+
166+
## Protobuf
167+
168+
Use protobuf for code generation with [protoc-gen-micro](https://github.com/micro/go-micro/tree/master/cmd/protoc-gen-micro)
169+
170+
## Server
171+
172+
The micro server is an api and web dashboard that provide a fixed entrypoint for seeing and querying services.
173+
174+
Run it like so
175+
176+
```
177+
micro server
178+
```
179+
180+
Then browse to [localhost:8080](http://localhost:8080)
181+
182+
### API Endpoints
183+
184+
The API provides a fixed HTTP entrypoint for calling services
185+
186+
```
187+
curl http://localhost:8080/api/helloworld/Helloworld/Call -d '{"name": "John"}'
188+
```
189+
See /api for more details and documentation for each service
190+
191+
### Web Dashboard
192+
193+
The web dashboard provides a modern, secure UI for managing and exploring your Micro services. Major features include:
194+
195+
- **Dynamic Service & Endpoint Forms**: Browse all registered services and endpoints. For each endpoint, a dynamic form is generated for easy testing and exploration.
196+
- **API Documentation**: The `/api` page lists all available services and endpoints, with request/response schemas and a sidebar for quick navigation. A documentation banner explains authentication requirements.
197+
- **JWT Authentication**: All login and token management uses a custom JWT utility. Passwords are securely stored with bcrypt. All `/api/x` endpoints and authenticated pages require an `Authorization: Bearer <token>` header (or `micro_token` cookie as fallback).
198+
- **Token Management**: The `/auth/tokens` page allows you to generate, view (obfuscated), and copy JWT tokens. Tokens are stored and can be revoked. When a user is deleted, all their tokens are revoked immediately.
199+
- **User Management**: The `/auth/users` page allows you to create, list, and delete users. Passwords are never shown or stored in plaintext.
200+
- **Token Revocation**: JWT tokens are stored and checked for revocation on every request. Revoked or deleted tokens are immediately invalidated.
201+
- **Security**: All protected endpoints use consistent authentication logic. Unauthorized or revoked tokens receive a 401 error. All sensitive actions require authentication.
202+
- **Logs & Status**: View service logs and status (PID, uptime, etc) directly from the dashboard.
203+
204+
To get started, run:
205+
206+
```
207+
micro server
208+
```
209+
210+
Then browse to [localhost:8080](http://localhost:8080) and log in with the default admin account (`admin`/`micro`).
211+
212+
> **Note:** See the `/api` page for details on API authentication and how to generate tokens for use with the HTTP API

cmd/cmd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ package cmd
44
import (
55
"fmt"
66
"math/rand"
7-
"sort"
87
"os"
8+
"sort"
99
"strings"
1010
"time"
1111

1212
"github.com/urfave/cli/v2"
13+
"go-micro.dev/v5/auth"
14+
"go-micro.dev/v5/broker"
15+
nbroker "go-micro.dev/v5/broker/nats"
16+
rabbit "go-micro.dev/v5/broker/rabbitmq"
1317
"go-micro.dev/v5/cache"
1418
"go-micro.dev/v5/cache/redis"
1519
"go-micro.dev/v5/client"
@@ -19,15 +23,11 @@ import (
1923
"go-micro.dev/v5/debug/profile/pprof"
2024
"go-micro.dev/v5/debug/trace"
2125
"go-micro.dev/v5/events"
22-
"go-micro.dev/v5/logger"
23-
mprofile "go-micro.dev/v5/profile"
24-
"go-micro.dev/v5/auth"
25-
"go-micro.dev/v5/broker"
26-
nbroker "go-micro.dev/v5/broker/nats"
27-
rabbit "go-micro.dev/v5/broker/rabbitmq"
2826
"go-micro.dev/v5/genai"
2927
"go-micro.dev/v5/genai/gemini"
3028
"go-micro.dev/v5/genai/openai"
29+
"go-micro.dev/v5/logger"
30+
mprofile "go-micro.dev/v5/profile"
3131
"go-micro.dev/v5/registry"
3232
"go-micro.dev/v5/registry/consul"
3333
"go-micro.dev/v5/registry/etcd"

0 commit comments

Comments
 (0)