fix(config): trim trailing slash from base_url in config layer#68
Open
azbh111 wants to merge 1 commit intoriba2534:mainfrom
Open
fix(config): trim trailing slash from base_url in config layer#68azbh111 wants to merge 1 commit intoriba2534:mainfrom
azbh111 wants to merge 1 commit intoriba2534:mainfrom
Conversation
Normalize BaseURL by removing trailing slashes in config.Init(), so all downstream consumers (SDK client, raw HTTP requests in message.go, oauth.go, etc.) automatically get a clean URL. This prevents double-slash in API paths (e.g. https://host//open-apis/...) which causes 404 on some private deployments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
config.Init()中对BaseURL统一执行strings.TrimRight(url, "/"),从源头消除尾部斜杠Background
私有化部署用户在
config.yaml中配置base_url时,尾部可能带斜杠(如https://private-deploy.example.com/)。飞书 SDK 和项目中多处手动拼接路径时会产生双斜杠(https://host//open-apis/...),部分私有化部署服务器对双斜杠返回 404,导致所有 API 调用失败。此 PR 是 #66 的改进方案。#66 仅在
client.go的GetClient()做 TrimRight,但message.go(2 处)和oauth.go(2 处)中手动拼接 URL 的代码未覆盖。维护者建议在 config 层统一处理。新方案将 TrimRight 移至
config.Init()—— 所有配置的唯一入口点,无论配置来源(环境变量、配置文件、默认值),BaseURL 都在此处完成清理,所有下游消费方自动受益,无需逐个修补。Changes
internal/config/config.goInit()中Unmarshal后新增strings.TrimRight(cfg.BaseURL, "/")internal/config/config_test.goTestInit_BaseURLTrimsTrailingSlash(表驱动,3 子测试)和TestInit_BaseURLTrimsTrailingSlashFromFileTest Plan
常规检查
go build ./...编译通过go vet ./...静态检查通过go clean -testcache && go test ./...全部测试通过新增用例
TestInit_BaseURLTrimsTrailingSlash:表驱动覆盖单斜杠/、多斜杠///、无斜杠三种输入(环境变量来源)TestInit_BaseURLTrimsTrailingSlashFromFile:配置文件来源的尾部斜杠处理