mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-23 21:44:41 +02:00
Generated docs for the following files:
This commit is contained in:
@@ -1,3 +1,26 @@
|
|||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
Here's a minimal Go Micro service demonstrating the architecture:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-micro.dev/v5"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
service := micro.NewService(
|
||||||
|
micro.Name("example"),
|
||||||
|
)
|
||||||
|
service.Init()
|
||||||
|
if err := service.Run(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
An overview of the Go Micro architecture
|
An overview of the Go Micro architecture
|
||||||
|
|||||||
54
internal/website/docs/broker.md
Normal file
54
internal/website/docs/broker.md
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# Broker
|
||||||
|
|
||||||
|
The broker provides pub/sub messaging for Go Micro services.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Publish messages to topics
|
||||||
|
- Subscribe to topics
|
||||||
|
- Multiple broker implementations
|
||||||
|
|
||||||
|
## Implementations
|
||||||
|
Supported brokers include:
|
||||||
|
- Memory (default)
|
||||||
|
- NATS
|
||||||
|
- RabbitMQ
|
||||||
|
|
||||||
|
Configure the broker when creating your service as needed.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
Here's how to use the broker in your Go Micro service:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-micro.dev/v5"
|
||||||
|
"go-micro.dev/v5/broker"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
service := micro.NewService()
|
||||||
|
service.Init()
|
||||||
|
|
||||||
|
// Publish a message
|
||||||
|
if err := broker.Publish("topic", &broker.Message{Body: []byte("hello world")}); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subscribe to a topic
|
||||||
|
_, err := broker.Subscribe("topic", func(p broker.Event) error {
|
||||||
|
log.Printf("Received message: %s", string(p.Message().Body))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the service
|
||||||
|
if err := service.Run(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
43
internal/website/docs/client-server.md
Normal file
43
internal/website/docs/client-server.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Client/Server
|
||||||
|
|
||||||
|
Go Micro uses a client/server model for RPC communication between services.
|
||||||
|
|
||||||
|
## Client
|
||||||
|
The client is used to make requests to other services.
|
||||||
|
|
||||||
|
## Server
|
||||||
|
The server handles incoming requests.
|
||||||
|
|
||||||
|
Both client and server are pluggable and support middleware wrappers for additional functionality.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
Here's how to define a simple handler and register it with a Go Micro server:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"go-micro.dev/v5"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Greeter struct{}
|
||||||
|
|
||||||
|
func (g *Greeter) Hello(ctx context.Context, req *struct{}, rsp *struct{Msg string}) error {
|
||||||
|
rsp.Msg = "Hello, world!"
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
service := micro.NewService(
|
||||||
|
micro.Name("greeter"),
|
||||||
|
)
|
||||||
|
service.Init()
|
||||||
|
micro.RegisterHandler(service.Server(), new(Greeter))
|
||||||
|
if err := service.Run(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
39
internal/website/docs/registry.md
Normal file
39
internal/website/docs/registry.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Registry
|
||||||
|
|
||||||
|
The registry is responsible for service discovery in Go Micro. It allows services to register themselves and discover other services.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Service registration and deregistration
|
||||||
|
- Service lookup
|
||||||
|
- Watch for changes
|
||||||
|
|
||||||
|
## Implementations
|
||||||
|
Go Micro supports multiple registry backends, including:
|
||||||
|
- MDNS (default)
|
||||||
|
- Consul
|
||||||
|
- Etcd
|
||||||
|
- NATS
|
||||||
|
|
||||||
|
You can configure the registry when initializing your service.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
Here's how to use a custom registry (e.g., Consul) in your Go Micro service:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-micro.dev/v5"
|
||||||
|
"go-micro.dev/v5/registry/consul"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reg := consul.NewRegistry()
|
||||||
|
service := micro.NewService(
|
||||||
|
micro.Registry(reg),
|
||||||
|
)
|
||||||
|
service.Init()
|
||||||
|
service.Run()
|
||||||
|
}
|
||||||
|
```
|
||||||
47
internal/website/docs/store.md
Normal file
47
internal/website/docs/store.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# Store
|
||||||
|
|
||||||
|
The store provides a pluggable interface for data storage in Go Micro.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Key-value storage
|
||||||
|
- Multiple backend support
|
||||||
|
|
||||||
|
## Implementations
|
||||||
|
Supported stores include:
|
||||||
|
- Memory (default)
|
||||||
|
- File
|
||||||
|
- MySQL
|
||||||
|
- Redis
|
||||||
|
|
||||||
|
Configure the store as needed for your application.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
Here's how to use the store in your Go Micro service:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-micro.dev/v5"
|
||||||
|
"go-micro.dev/v5/store"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
service := micro.NewService()
|
||||||
|
service.Init()
|
||||||
|
|
||||||
|
// Write a record
|
||||||
|
if err := store.Write(&store.Record{Key: "foo", Value: []byte("bar")}); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read a record
|
||||||
|
recs, err := store.Read("foo")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Printf("Read value: %s", string(recs[0].Value))
|
||||||
|
}
|
||||||
|
```
|
||||||
36
internal/website/docs/transport.md
Normal file
36
internal/website/docs/transport.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Transport
|
||||||
|
|
||||||
|
The transport layer is responsible for communication between services.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
- Pluggable transport implementations
|
||||||
|
- Secure and efficient communication
|
||||||
|
|
||||||
|
## Implementations
|
||||||
|
Supported transports include:
|
||||||
|
- TCP (default)
|
||||||
|
- gRPC
|
||||||
|
|
||||||
|
You can specify the transport when initializing your service.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
Here's how to use a custom transport (e.g., gRPC) in your Go Micro service:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-micro.dev/v5"
|
||||||
|
"go-micro.dev/v5/transport/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
t := grpc.NewTransport()
|
||||||
|
service := micro.NewService(
|
||||||
|
micro.Transport(t),
|
||||||
|
)
|
||||||
|
service.Init()
|
||||||
|
service.Run()
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user