当前位置:网站首页>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!
边栏推荐
- Facebook was officially renamed meta, and the digital twin meta universe was applied!
- The cloud University of "digital and real integration, CO building authentic Internet" is surging forward
- Using the database middleware MYCAT to realize read-write separation (dual master and dual slave)
- Data acquisition and transmission instrument environmental pollution monitoring of iron and steel plant
- Uipickerview show and hide animation
- Grpc: adjust data transfer size limit
- How to build a cloud game server what needs to be considered to build a cloud game server
- How to view the speech synthesis platform how to use the speech synthesis platform
- [Tencent cloud load balancing CLB] cross region binding 2.0 (new version) idc-ip best practices!
- CPS November additional incentive rules
猜你喜欢
随机推荐
How to obtain the information of easydss single / multiple live streams through the API interface?
Simple use of notification
[security] Tencent cloud double 12 is not limited to new and old users! Safe sub venue - discount guide! Unlimited account types!
Dry goods collection | the heaviest content collection of Tencent digital ecology Conference!
What are the main functions of DNS? What are the benefits of IP address translation
Efficient Internet access and systematic learning
How to bind EIP to access public network in tke cluster fixed IP mode pod
How to build a website? These things should be paid attention to
The dealer management and control platform in the leather industry simplifies the purchase approval process and easily controls agents
Internal reasons for cloud desktop unable to connect to the server and external reasons for cloud desktop connection failure
How to quickly handle third-party login and easy to expand?
Which is a good human voice synthesis platform? What are the human voice synthesis application scenarios
How to build an enterprise website? Is it difficult?
The easydss on demand file upload interface calls postman to report an error. Failed to upload the file?
How to design and make ppt gradient effect?
Implementing an ORM framework against SQL injection with builder mode
Comparison of four dynamic routes: Rip, OSPF, Isis, BGP
[Tencent cloud double 12.12] from 56 yuan! New users of Tencent cloud buy for the first time, which is more cost-effective!
How to build your own cloud game server and what are the building steps
Evaluation index of machine learning model


