【发布时间】:2020-11-21 15:17:21
【问题描述】:
Go 中是否有一种直接的方式来修改 URL/URI,而不必使用正则表达式来提取组件(即我正在寻找一种确定性的“经过验证的”方式/方法)。
例如,我有两种类型的 URL 被发送到我的应用程序:
http://wiley.coyote.acme.co/this/is/a/long/path?param1=123&param2=456https://road.runner.acme.co/another/long/path?meep=meep
我需要做的是重写 URL,使参数列表和端点/路径保持不变,但协议从 http 更改为 https(除非它已经是 https),并且整个主机名/FQDN 需要更改为 egghead.local。因此,例如,上面的两个 URL 将变为:
https://egghead.local/this/is/a/long/path?param1=123&param2=456https://egghead.local/another/long/path?meep=meep
是否有可靠/成熟的方法来处理这个问题(例如最好不使用正则表达式)?
【问题讨论】:
标签: string go url url-rewriting substring