Conversation
Contributor
There was a problem hiding this comment.
Hey - 我发现了 1 个问题
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="agent/go-service/pkg/pienv/pienv.go" line_range="161-162" />
<code_context>
+ })
+}
+
+// Get returns the global Env. Returns nil if Init has not been called.
+func Get() *Env {
+ return global
+}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** 当没有调用 `Init` 时,`Get` 和相关访问器会静默返回零值,这可能会掩盖配置问题。
因为 `Get()` 可能返回 `nil`,而辅助函数会默认返回空字符串,所以在 `Init` 调用之前使用它们会静默失败,并且会与之前使用 `os.Getenv` 的行为不同(例如,如果漏掉了 `pienv.Init`,`i18n.Init` 将总是回退到 `DefaultLang`)。为避免这种情况,可以让 `Get()`/这些辅助函数调用 `once.Do(Init)`,从而在没有显式初始化的情况下仍然安全;或者在检测到未初始化的访问时进行日志记录或触发 panic,以便及早暴露配置错误。
建议实现:
```golang
// Get returns the global Env.
// It panics if Init has not been called to surface configuration issues early.
func Get() *Env {
if global == nil {
panic("pienv.Get called before pienv.Init; ensure Init is invoked during service startup")
}
return global
}
```
如果存在类似 `String()`、`Int()` 等辅助函数,之前是基于 `Get()` 可能返回 `nil` 的假设,那么现在它们依赖这种 panic 行为来保护未初始化访问,因此不需要进一步修改。不过,如果有任何调用点之前防御性地写了 `if env := Get(); env != nil { ... }` 这样的判断,这些检查现在已经多余,可以简化掉,因为在此改动后 `Get()` 将不会再返回 `nil`。
</issue_to_address>帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据你的反馈改进后续的 review。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="agent/go-service/pkg/pienv/pienv.go" line_range="161-162" />
<code_context>
+ })
+}
+
+// Get returns the global Env. Returns nil if Init has not been called.
+func Get() *Env {
+ return global
+}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** `Get` and the accessors silently return zero values when `Init` was not called, which can mask configuration issues.
Because `Get()` may return `nil` and the helpers default to empty strings, calling them before `Init` will fail silently and can change behavior compared to the previous `os.Getenv` usage (e.g. `i18n.Init` will always fall back to `DefaultLang` if `pienv.Init` is missed). To avoid this, either make `Get()`/the helpers call `once.Do(Init)` so they’re safe without explicit initialization, or detect uninitialized access (log or panic) to surface configuration bugs early.
Suggested implementation:
```golang
// Get returns the global Env.
// It panics if Init has not been called to surface configuration issues early.
func Get() *Env {
if global == nil {
panic("pienv.Get called before pienv.Init; ensure Init is invoked during service startup")
}
return global
}
```
If there are helper functions like `String()`, `Int()`, etc. that previously assumed `Get()` could return `nil`, they now rely on this panic behavior to protect against uninitialized access and don’t need further modification. However, if any call sites were defensively checking `if env := Get(); env != nil { ... }`, those checks are now redundant and can be simplified, since `Get()` will never return `nil` after this change.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
zmdyy0318
approved these changes
Mar 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 为 go-service 引入一个全局 PI v2.5 环境变量管理器,用于集中读取/解析 PI_* 环境变量,并让 i18n 语言选择改为基于该管理器的结果,统一入口避免各处散落的 os.Getenv。
Changes:
- 新增
pkg/pienv:解析并缓存 PI v2.5 的 PI_* 环境变量(含 PI_CONTROLLER/PI_RESOURCE JSON)。 i18n.Init()改为通过pienv.ClientLanguage()获取语言,而非直接读取环境变量。main()启动时增加pienv.Init(),保证 i18n 初始化前已读取环境上下文。
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| agent/go-service/pkg/pienv/pienv.go | 新增 PI 环境变量解析与全局访问器(含 controller/resource JSON 解析与初始化日志)。 |
| agent/go-service/pkg/i18n/i18n.go | i18n 语言来源切换到 pienv,减少直接读环境变量的散落逻辑。 |
| agent/go-service/main.go | 启动流程中加入 pienv 初始化,确保 i18n 读取到 PI 语言信息。 |
Contributor
|
干啥的 |
dongwlin
approved these changes
Mar 25, 2026
Contributor
Author
UI 的语言、选择的控制器、资源、版本号 之类的 |
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 by Sourcery
引入集中式的 PI 环境管理器,并将其集成到 agent 服务的初始化流程中。
新功能:
增强点:
Original summary in English
Summary by Sourcery
Introduce a centralized PI environment manager and integrate it into the agent service initialization.
New Features:
Enhancements: