Skip to content

Commit

Permalink
Update wasm-go.md
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlanni authored Jul 1, 2024
1 parent 2e974e5 commit 939600a
Showing 1 changed file with 10 additions and 39 deletions.
49 changes: 10 additions & 39 deletions i18n/zh-cn/docusaurus-plugin-content-docs/current/user/wasm-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,48 +449,19 @@ func parseConfig(json gjson.Result, config *MyConfig, log wrapper.Log) error {
if config.requestPath == "" {
return errors.New("missing requestPath in config")
}
serviceSource := json.Get("serviceSource").String()
// 固定地址和dns类型的serviceName,为控制台中创建服务时指定
// nacos和k8s来源的serviceName,即服务注册时指定的原始名称
// 带服务类型的完整 FQDN 名称,例如 my-svc.dns, my-svc.static, service-provider.DEFAULT-GROUP.public.nacos, httpbin.my-ns.svc.cluster.local
serviceName := json.Get("serviceName").String()
servicePort := json.Get("servicePort").Int()
if serviceName == "" || servicePort == 0 {
return errors.New("invalid service config")
}
switch serviceSource {
case "k8s":
namespace := json.Get("namespace").String()
config.client = wrapper.NewClusterClient(wrapper.K8sCluster{
ServiceName: serviceName,
Namespace: namespace,
Port: servicePort,
})
return nil
case "nacos":
namespace := json.Get("namespace").String()
config.client = wrapper.NewClusterClient(wrapper.NacosCluster{
ServiceName: serviceName,
NamespaceID: namespace,
Port: servicePort,
})
return nil
case "ip":
config.client = wrapper.NewClusterClient(wrapper.StaticIpCluster{
ServiceName: serviceName,
Port: servicePort,
})
return nil
case "dns":
domain := json.Get("domain").String()
config.client = wrapper.NewClusterClient(wrapper.DnsCluster{
ServiceName: serviceName,
Port: servicePort,
Domain: domain,
})
return nil
default:
return errors.New("unknown service source: " + serviceSource)
if servicePort == 0 {
if strings.HasSuffix(serviceName, ".static") {
// 静态IP类型服务的逻辑端口是80
servicePort = 80
}
}
config.client = wrapper.NewClusterClient(wrapper.FQDNCluster{
FQDN: serviceName,
Port: servicePort,
})
}
func onHttpRequestHeaders(ctx wrapper.HttpContext, config MyConfig, log wrapper.Log) types.Action {
Expand Down

0 comments on commit 939600a

Please sign in to comment.