Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: export the Gateway/internal. methods #3985

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ev11ccaatt
Copy link

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
}
`

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
`
	for _, mapping := range config.Mappings {
		gateway.Methods = append(gateway.Methods, gateway.MethodConver(gateway.Method{
			HttpMethod: mapping.Method,
			HttpPath:   adjustHttpPath(mapping.Path),
			RpcPath:    mapping.RpcPath,
		}))
	}`
@ev11ccaatt ev11ccaatt changed the title export the Gateway/internal. methods Add: export the Gateway/internal. methods Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant