当前位置:网站首页>Grc: GRC interface is mixed with restful API
Grc: GRC interface is mixed with restful API
2022-06-24 02:37:00 【Trespass 】
Introduce
This article will show you how to gRPC Mixed use in microservices Restful API.
Here we are not referring to gRPC Interface to Restful API, But let different gRPC Interface and Restful API coexistence .
grpc-gateway This feature is already supported .
We will use rk-boot To start up gRPC service .
Please visit the following address for a complete tutorial :
install
go get github.com/rookie-ninja/rk-boot go get github.com/rookie-ninja/rk-grpc
Quick start
In this case , Will not write any gRPC Interface , We will be in gRPC Add an independent... To the service Restful API.
1. establish boot.yaml
---
grpc:
- name: greeter # Name of grpc entry
port: 8080 # Port of grpc entry
enabled: true # Enable grpc entry2. establish main.go
stay grpc-gateway Create a GET /custom Method .
adopt boot.GetGrpcEntry("greeter").GwMux.HandlePath() Method to add a custom interface . For example, file upload .
package main
import (
"context"
"github.com/rookie-ninja/rk-boot"
"github.com/rookie-ninja/rk-grpc/boot"
"net/http"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Get grpc entry with name
grpcEntry := boot.GetEntry("greeter").(*rkgrpc.GrpcEntry)
// !!!!!!
// This codes should be located after Bootstrap()
grpcEntry.GwMux.HandlePath("GET", "/custom", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
w.Write([]byte("Custom routes!"))
})
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}3. verification
$ curl "localhost:8080/custom" Custom routes!
边栏推荐
- Block
- Build your own cloud game server. What if the cloud game server is attacked
- What is data matrix code
- How to use the cloud game server is the cloud server stable
- Face recognition using cidetector
- How to access easynvr management platform through web pages without data?
- How to handle the abnormal state of easycvr national standard cascading superior display?
- How to quickly handle third-party login and easy to expand?
- Visual AI, first!
- Deep and shallow copy
猜你喜欢
随机推荐
The technical route is based on UE4 for secondary development
Centeros environment setup
Is it illegal to use someone else's trademark to register a domain name? What should we pay attention to when registering a domain name?
Optimization of Clickhouse ConnectionPool link pool
Block
What are the conditions for trademark registration? How long does it take to register a trademark?
Engineer culture: why doesn't bat call the boss
Leetcode838: push domino (medium)
Is a trademark domain name useful? How long does it take to register a domain name?
Opengl: how to use shader to convert RGBA to nv21 image format? (open source for the first time in the whole network)
Where is the domain name filed? What materials are required for domain name filing?
Buddha's foot before examination: the third bullet of leetcode
How does easydss solve the problem that the concurrency is too large and the disk read / write cannot keep up?
A detailed explanation of the laser slam framework logo-loam
How to build a website? What needs attention?
Visual AI, first!
[supply chain • case] Tianneng group: the key to understanding the leading battery manufacturer to achieve the first profit fault
Comparison of four dynamic routes: Rip, OSPF, Isis, BGP
Coding -- the leader of R & D tools in the cloud native Era
Pan micro reached cooperation with Tencent to help enterprises connect with banking services and support enterprise digital upgrading


