2 Star 2 Fork 0

jmash / jmash

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
百圆汽车保养 提交于 2024-02-26 21:17 . Go Package Error.
package main
import (
"context"
"log"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"gitee.com/jmash/jmash/trunk/jmash-core-gateway/src/jmash"
servicepb "gitee.com/jmash/jmash/trunk/jmash-dict/jmash-dict-gateway/src/jmash/dict"
)
func main() {
// Create a client connection to the gRPC server we just started
// This is where the gRPC-Gateway proxies the requests
conn, err := grpc.DialContext(
context.Background(),
"0.0.0.0:50051",
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.Fatalln("Failed to dial server:", err)
}
gwmux := runtime.NewServeMux()
// Register Dict
err = servicepb.RegisterDictHandler(context.Background(), gwmux, conn)
if err != nil {
log.Fatalln("Failed to register gateway:", err)
}
log.Println("OpenApi Starting !")
// Serve the Grpc GateWay And OpenApi,
mux := http.NewServeMux()
mux.Handle("/", gwmux)
fs := http.FileServer(http.Dir("openapi"))
mux.Handle("/openapi/", http.StripPrefix("/openapi", fs))
log.Println("Serving gRPC-Gateway on http://0.0.0.0:8090")
handler := jmash.AllowCORS(mux)
err = http.ListenAndServe(":8090", handler)
if err != nil {
log.Fatal(err)
}
}
Java
1
https://gitee.com/jmash/jmash.git
git@gitee.com:jmash/jmash.git
jmash
jmash
jmash
74b440458984

搜索帮助

53164aa7 5694891 3bd8fe86 5694891