1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-11-23 21:44:41 +02:00

updates for syntax highlighting

This commit is contained in:
Asim Aslam
2025-11-13 18:17:45 +00:00
parent eef06fcf01
commit e755e4a823
7 changed files with 38 additions and 29 deletions

View File

@@ -96,8 +96,8 @@ func main() {
Using the built-in configuration flags/env vars (no code changes):
```
MICRO_BROKER=nats MICRO_BROKER_ADDRESS=nats://127.0.0.1:4222 micro server
```bash
MICRO_BROKER=nats MICRO_BROKER_ADDRESS=nats://127.0.0.1:4222 go run main.go
```
Common variables:

View File

@@ -6,7 +6,7 @@ layout: default
To make use of Go Micro
```golang
```bash
go get go-micro.dev/v5@latest
```
@@ -14,7 +14,7 @@ go get go-micro.dev/v5@latest
This is a basic example of how you'd create a service and register a handler in pure Go.
```
```bash
mkdir helloworld
cd helloworld
go mod init
@@ -23,7 +23,7 @@ go get go-micro.dev/v5@latest
Write the following into `main.go`
```golang
```go
package main
import (
@@ -62,19 +62,19 @@ func main() {
Now run the service
```
```bash
go run main.go
```
Take a note of the address with the log line
```
```text
Transport [http] Listening on [::]:35823
```
Now you can call the service
```
```bash
curl -XPOST \
-H 'Content-Type: application/json' \
-H 'Micro-Endpoint: Say.Hello' \
@@ -86,7 +86,7 @@ curl -XPOST \
To set a fixed address by specifying it as an option to service, note the change from `New` to `NewService`
```golang
```go
service := micro.NewService(
micro.Name("helloworld"),
micro.Address(":8080"),
@@ -95,7 +95,7 @@ service := micro.NewService(
Alternatively use `MICRO_SERVER_ADDRESS=:8080` as an env var
```
```bash
curl -XPOST \
-H 'Content-Type: application/json' \
-H 'Micro-Endpoint: Say.Hello' \
@@ -109,18 +109,18 @@ If you want to define services with protobuf you can use protoc-gen-micro (go-mi
Install the generator:
```
```bash
go install go-micro.dev/v5/cmd/protoc-gen-micro@latest
```
```
```bash
cd helloworld
mkdir proto
```
Edit a file `proto/helloworld.proto`
```
```proto
syntax = "proto3";
package greeter;
@@ -141,13 +141,13 @@ message Response {
You can now generate a client/server like so (ensure `$GOBIN` is on your `$PATH` so `protoc` can find `protoc-gen-micro`):
```
```bash
protoc --proto_path=. --micro_out=. --go_out=. helloworld.proto
```
In your `main.go` update the code to reference the generated code
```
```go
package main
import (
@@ -171,7 +171,7 @@ func main() {
service.Init()
// register handler
proto.RegisterSayHandler(service.Server(), &Say{})
pb.RegisterSayHandler(service.Server(), &Say{})
// run the service
service.Run()
@@ -180,7 +180,7 @@ func main() {
Now I can run this again
```
```bash
go run main.go
```
@@ -188,7 +188,7 @@ go run main.go
The generated code provides us a client
```
```go
package main
import (

View File

@@ -10,7 +10,7 @@ The Micro server is an optional API and dashboard that provides a fixed entrypoi
Install the CLI which includes the server command:
```
```bash
go install go-micro.dev/v5/cmd/micro@latest
```
@@ -18,7 +18,7 @@ go install go-micro.dev/v5/cmd/micro@latest
Start the server:
```
```bash
micro server
```

View File

@@ -87,10 +87,10 @@ func main() {
## Configure via environment
```
```bash
MICRO_STORE=postgres MICRO_STORE_ADDRESS=postgres://user:pass@127.0.0.1:5432/db \
MICRO_STORE_DATABASE=micro MICRO_STORE_TABLE=micro \
micro server
go run main.go
```
Common variables:

View File

@@ -60,8 +60,8 @@ func main() {
## Configure via environment
```
MICRO_TRANSPORT=nats MICRO_TRANSPORT_ADDRESS=nats://127.0.0.1:4222 micro server
```bash
MICRO_TRANSPORT=nats MICRO_TRANSPORT_ADDRESS=nats://127.0.0.1:4222 go run main.go
```
Common variables: