当前位置:网站首页>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!
边栏推荐
- The blue screen will be displayed at a remote location, and the error code kmode will be reported_ EXCEPTION_ NOT_ Handled, the DMP file has the keyword cdd dll
- Leetcode problem solving notes for slow ploughing of stupid cattle (dynamic update...)
- How to formulate a domain name trademark registration scheme? What if the plan is rejected?
- Create and mount large files
- Must the company domain name have a trademark registration? What if the registered domain name is rejected?
- The technical route is based on UE4 for secondary development
- [expense center] demand & problem feedback week is coming! Feedback wins a good gift!
- MySQL Cases-MySQL 8.0.26 bug ERROR 1064 (42000) at line1: You have an error
- What is a port? The most complete and strongest port number in history, collection!
- Tidb HTAP Getting Started Guide - how to add a copy of tiflash
猜你喜欢
随机推荐
Coding helps Jiangsu high-speed information to achieve organizational agility and R & D agility, leading the new infrastructure of Intelligent Transportation
How to obtain the information of easydss single / multiple live streams through the API interface?
Efficient Internet access and systematic learning
[expense center] demand & problem feedback week is coming! Feedback wins a good gift!
Cloud game cannot select a server cloud game server fees
Visual AI, first!
Leetcode problem solving notes for slow ploughing of stupid cattle (dynamic update...)
Face recognition using cidetector
A complete collection of SQL commands. Each command has an example. Xiaobai can become a God after reading it!
How to build your own website? Is it difficult?
Leetcode838: push domino (medium)
Tencent peace of mind ecological alliance was officially established as a linkage partner. Open technology helps "digital agriculture"
How does easydss solve the problem that the concurrency is too large and the disk read / write cannot keep up?
Start tcapulusdb process
How to build your own cloud game server and what are the building steps
Block
How to understand EDI requirements of trading partners
NFT metauniverse and the relationship between Games Golden Finance
How to quickly handle third-party login and easy to expand?
5g Gigabit router dual band industrial grade


