refactor: clean up verbose and redundant comments
Trim or remove comments that: - State the obvious (function names already convey purpose) - Repeat what the code clearly shows - Are excessively long without adding value Keep comments that explain *why*, not *what*.
This commit is contained in:
parent
805e7ffdc2
commit
5b942a5fd6
11 changed files with 16 additions and 102 deletions
|
|
@ -22,14 +22,10 @@ import (
|
|||
)
|
||||
|
||||
// MainResult represents one element of the `results` array.
|
||||
//
|
||||
// The API returns many additional keys beyond what templates use. To keep the
|
||||
// contract stable for proxying/merging, we preserve all unknown keys in
|
||||
// `raw` and re-emit them via MarshalJSON.
|
||||
// Unknown keys are preserved in `raw` and re-emitted via MarshalJSON.
|
||||
type MainResult struct {
|
||||
raw map[string]any
|
||||
|
||||
// Common fields used by templates (RSS uses: title, url, content, pubdate).
|
||||
Template string `json:"template"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
|
|
@ -45,17 +41,13 @@ type MainResult struct {
|
|||
Positions []int `json:"positions"`
|
||||
Engines []string `json:"engines"`
|
||||
|
||||
// These fields exist in the MainResult base; keep them so downstream
|
||||
// callers can generate richer output later.
|
||||
OpenGroup bool `json:"open_group"`
|
||||
CloseGroup bool `json:"close_group"`
|
||||
|
||||
// parsed_url is emitted as a tuple; we preserve it as-is.
|
||||
ParsedURL any `json:"parsed_url"`
|
||||
}
|
||||
|
||||
func (mr *MainResult) UnmarshalJSON(data []byte) error {
|
||||
// Preserve the full object.
|
||||
dec := json.NewDecoder(bytes.NewReader(data))
|
||||
dec.UseNumber()
|
||||
|
||||
|
|
@ -66,7 +58,6 @@ func (mr *MainResult) UnmarshalJSON(data []byte) error {
|
|||
|
||||
mr.raw = m
|
||||
|
||||
// Fill the typed/common fields (best-effort; don't fail if types differ).
|
||||
mr.Template = stringOrEmpty(m["template"])
|
||||
mr.Title = stringOrEmpty(m["title"])
|
||||
mr.Content = stringOrEmpty(m["content"])
|
||||
|
|
@ -104,12 +95,10 @@ func (mr *MainResult) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
|
||||
func (mr MainResult) MarshalJSON() ([]byte, error) {
|
||||
// If we came from upstream JSON, preserve all keys exactly.
|
||||
if mr.raw != nil {
|
||||
return json.Marshal(mr.raw)
|
||||
}
|
||||
|
||||
// Otherwise, marshal the known fields.
|
||||
m := map[string]any{
|
||||
"template": mr.Template,
|
||||
"title": mr.Title,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue