Add: export the Gateway/internal. methods #3985
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
export the methods to avoid proto.GetExtension can't get any thing from rpc server,export the methods means i can add the methods in gateway/main.go like
`package main
import (
"flag"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/gateway"
"gopkg.in/yaml.v2"
"log"
"os"
"strings"
)
var file = "etc/route.yaml"
var configFile = flag.String("f", "etc/versionApi.yaml", "config file")
type RouteMapping struct {
Method string
yaml:"Method"
Path string
yaml:"Path"
RpcPath string
yaml:"RpcPath"
}
type Mappings struct {
Mappings []RouteMapping
yaml:"Mappings"
}
func main() {
flag.Parse()
var c gateway.GatewayConf
conf.MustLoad(*configFile, &c)
addMapping()
gw := gateway.MustNewServer(c)
defer gw.Stop()
gw.Start()
}
func addMapping() {
data, err := os.ReadFile(file)
if err != nil {
log.Fatalf("无法读取 YAML 文件:%v", err)
}
var config Mappings
err = yaml.Unmarshal(data, &config)
if err != nil {
log.Fatalf("无法解析 YAML 数据:%v", err)
}
for _, mapping := range config.Mappings {
gateway.Methods = append(gateway.Methods, gateway.MethodConver(gateway.Method{
HttpMethod: mapping.Method,
HttpPath: adjustHttpPath(mapping.Path),
RpcPath: mapping.RpcPath,
}))
}
}
func adjustHttpPath(path string) string {
path = strings.ReplaceAll(path, "{", ":")
path = strings.ReplaceAll(path, "}", "")
return path
}
`