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:
10
README.md
10
README.md
@@ -49,13 +49,13 @@ in the plugins repo. State and persistence becomes a core requirement beyond pro
|
||||
|
||||
To make use of Go Micro
|
||||
|
||||
```golang
|
||||
```bash
|
||||
go get go-micro.dev/v5@latest
|
||||
```
|
||||
|
||||
Create a service and register a handler
|
||||
|
||||
```golang
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -91,7 +91,7 @@ func main() {
|
||||
|
||||
Set a fixed address
|
||||
|
||||
```golang
|
||||
```go
|
||||
service := micro.NewService(
|
||||
micro.Name("helloworld"),
|
||||
micro.Address(":8080"),
|
||||
@@ -100,7 +100,7 @@ service := micro.NewService(
|
||||
|
||||
Call it via curl
|
||||
|
||||
```
|
||||
```bash
|
||||
curl -XPOST \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Micro-Endpoint: Say.Hello' \
|
||||
@@ -116,7 +116,7 @@ There's a new `genai` package for generative AI capabilities.
|
||||
|
||||
Install the code generator and see usage in the docs:
|
||||
|
||||
```
|
||||
```bash
|
||||
go install go-micro.dev/v5/cmd/protoc-gen-micro@latest
|
||||
```
|
||||
|
||||
|
||||
@@ -4,3 +4,12 @@ baseurl: "" # the subpath of your site, e.g. /blog
|
||||
url: "" # the base hostname & protocol for your site, e.g. http://example.com
|
||||
|
||||
theme: jekyll-theme-primer
|
||||
|
||||
# Enable syntax highlighting
|
||||
highlighter: rouge
|
||||
markdown: kramdown
|
||||
kramdown:
|
||||
input: GFM
|
||||
syntax_highlighter: rouge
|
||||
syntax_highlighter_opts:
|
||||
line_numbers: false
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user