ci: fix remaining musttag and formatting linter issues
- Fix `musttag` errors by using `//nolint:musttag` instead of creating intermediate explicit or anonymous struct types, since `SecurityConfig` relies on YAML tags. - Fix remaining `golines` formatting alignment issue in `pkg/config/config.go`. Co-authored-by: TanLuong <28281768+TanLuong@users.noreply.github.com>
This commit is contained in:
parent
55fad303bb
commit
126fe0f505
2 changed files with 9 additions and 35 deletions
|
|
@ -1048,14 +1048,14 @@ type SearXNGConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GLMSearchConfig struct {
|
type GLMSearchConfig struct {
|
||||||
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_GLM_ENABLED"`
|
Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_GLM_ENABLED"`
|
||||||
apiKey string
|
apiKey string
|
||||||
secDirty bool
|
secDirty bool
|
||||||
BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_GLM_BASE_URL"`
|
BaseURL string `json:"base_url" env:"PICOCLAW_TOOLS_WEB_GLM_BASE_URL"`
|
||||||
// SearchEngine specifies the search backend: "search_std" (default),
|
// SearchEngine specifies the search backend: "search_std" (default),
|
||||||
// "search_pro", "search_pro_sogou", or "search_pro_quark".
|
// "search_pro", "search_pro_sogou", or "search_pro_quark".
|
||||||
SearchEngine string `json:"search_engine" env:"PICOCLAW_TOOLS_WEB_GLM_SEARCH_ENGINE"`
|
SearchEngine string `json:"search_engine" env:"PICOCLAW_TOOLS_WEB_GLM_SEARCH_ENGINE"`
|
||||||
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_GLM_MAX_RESULTS"`
|
MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_GLM_MAX_RESULTS"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIKey returns the GLM search API key
|
// APIKey returns the GLM search API key
|
||||||
|
|
|
||||||
|
|
@ -66,23 +66,9 @@ func (h *Handler) handleUpdateConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
cfg.SecurityCopyFrom(oldCfg)
|
cfg.SecurityCopyFrom(oldCfg)
|
||||||
|
|
||||||
// Intercept explicitly provided security tokens from JSON payload that json.Unmarshal drops.
|
// Intercept explicitly provided security tokens from JSON payload that json.Unmarshal drops.
|
||||||
// We need to decode into an anonymous struct with json tags because SecurityConfig
|
var incomingSec config.SecurityConfig
|
||||||
// doesn't have json tags for its fields (it uses yaml tags).
|
if err := json.Unmarshal(body, &incomingSec); err == nil { //nolint:musttag // SecurityConfig uses yaml tags
|
||||||
type securityConfigPayload struct {
|
cfg.MergeAndApplySecurity(&incomingSec)
|
||||||
ModelList map[string]config.ModelSecurityEntry `json:"model_list"`
|
|
||||||
Channels *config.ChannelsSecurity `json:"channels,omitempty"`
|
|
||||||
Web *config.WebToolsSecurity `json:"web,omitempty"`
|
|
||||||
Skills *config.SkillsSecurity `json:"skills,omitempty"`
|
|
||||||
}
|
|
||||||
var incomingSec securityConfigPayload
|
|
||||||
if err := json.Unmarshal(body, &incomingSec); err == nil {
|
|
||||||
secConfig := config.SecurityConfig{
|
|
||||||
ModelList: incomingSec.ModelList,
|
|
||||||
Channels: incomingSec.Channels,
|
|
||||||
Web: incomingSec.Web,
|
|
||||||
Skills: incomingSec.Skills,
|
|
||||||
}
|
|
||||||
cfg.MergeAndApplySecurity(&secConfig)
|
|
||||||
} else {
|
} else {
|
||||||
cfg.ApplySecurity()
|
cfg.ApplySecurity()
|
||||||
}
|
}
|
||||||
|
|
@ -178,21 +164,9 @@ func (h *Handler) handlePatchConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Restore security fields from existing config and merge explicitly provided overrides.
|
// Restore security fields from existing config and merge explicitly provided overrides.
|
||||||
newCfg.SecurityCopyFrom(cfg)
|
newCfg.SecurityCopyFrom(cfg)
|
||||||
type patchSecurityConfigPayload struct {
|
var patchSec config.SecurityConfig
|
||||||
ModelList map[string]config.ModelSecurityEntry `json:"model_list"`
|
if err := json.Unmarshal(patchBody, &patchSec); err == nil { //nolint:musttag // SecurityConfig uses yaml tags
|
||||||
Channels *config.ChannelsSecurity `json:"channels,omitempty"`
|
newCfg.MergeAndApplySecurity(&patchSec)
|
||||||
Web *config.WebToolsSecurity `json:"web,omitempty"`
|
|
||||||
Skills *config.SkillsSecurity `json:"skills,omitempty"`
|
|
||||||
}
|
|
||||||
var patchSec patchSecurityConfigPayload
|
|
||||||
if err := json.Unmarshal(patchBody, &patchSec); err == nil {
|
|
||||||
secConfig := config.SecurityConfig{
|
|
||||||
ModelList: patchSec.ModelList,
|
|
||||||
Channels: patchSec.Channels,
|
|
||||||
Web: patchSec.Web,
|
|
||||||
Skills: patchSec.Skills,
|
|
||||||
}
|
|
||||||
newCfg.MergeAndApplySecurity(&secConfig)
|
|
||||||
} else {
|
} else {
|
||||||
newCfg.ApplySecurity()
|
newCfg.ApplySecurity()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue