[pkgsite] internal/api: adjust symbols output format

0 views
Skip to first unread message

Hyang-Ah Hana Kim (Gerrit)

unread,
Apr 28, 2026, 6:58:29 PM (10 hours ago) Apr 28
to goph...@pubsubhelper.golang.org, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

Hyang-Ah Hana Kim has uploaded the change for review

Commit message

internal/api: adjust symbols output format

The current type repeats module/version fields for every symbol.
This CL explores a different format to reduce duplication.
Change-Id: I4c59cd2e387b53bb9bf00de1e1a8c14cc26c04e6

Change diff

diff --git a/cmd/internal/pkgsite-cli/client/client.go b/cmd/internal/pkgsite-cli/client/client.go
index e50784a..e8eec81 100644
--- a/cmd/internal/pkgsite-cli/client/client.go
+++ b/cmd/internal/pkgsite-cli/client/client.go
@@ -159,11 +159,11 @@
}
u := c.server.JoinPath("v1", "symbols", path)
u.RawQuery = q.Encode()
- var resp PaginatedResponse[Symbol]
+ var resp PackageSymbols
if err := c.get(ctx, u.String(), &resp); err != nil {
return nil, err
}
- return &resp, nil
+ return &resp.Symbols, nil
}

// ImportedByOptions contains options for GetImportedBy.
diff --git a/cmd/internal/pkgsite-cli/client/client_test.go b/cmd/internal/pkgsite-cli/client/client_test.go
index 2a0069a..9052c90 100644
--- a/cmd/internal/pkgsite-cli/client/client_test.go
+++ b/cmd/internal/pkgsite-cli/client/client_test.go
@@ -202,13 +202,17 @@

func TestGetSymbols(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- json.NewEncoder(w).Encode(PaginatedResponse[Symbol]{
- Items: []Symbol{{
- Name: "Marshal",
- Kind: "func",
- Synopsis: "func Marshal(v any) ([]byte, error)",
- }},
- Total: 1,
+ json.NewEncoder(w).Encode(PackageSymbols{
+ ModulePath: "std",
+ Version: "go1.26.0",
+ Symbols: PaginatedResponse[Symbol]{
+ Items: []Symbol{{
+ Name: "Marshal",
+ Kind: "func",
+ Synopsis: "func Marshal(v any) ([]byte, error)",
+ }},
+ Total: 1,
+ },
})
}))
defer srv.Close()
diff --git a/cmd/internal/pkgsite-cli/client/types_gen.go b/cmd/internal/pkgsite-cli/client/types_gen.go
index 70a9b0e..22a7ddd 100644
--- a/cmd/internal/pkgsite-cli/client/types_gen.go
+++ b/cmd/internal/pkgsite-cli/client/types_gen.go
@@ -80,14 +80,19 @@
Contents string `json:"contents"`
}

-// Symbol is a symbol in /v1/symbols/{packagePath}.
+// PackageSymbols is the response for /v1/symbols/{packagePath}.
+type PackageSymbols struct {
+ ModulePath string `json:"modulePath"`
+ Version string `json:"version"`
+ Symbols PaginatedResponse[Symbol] `json:"symbols"`
+}
+
+// Symbol is a symbol in a package.
type Symbol struct {
- ModulePath string `json:"modulePath"`
- Version string `json:"version"`
- Name string `json:"name"`
- Kind string `json:"kind"`
- Synopsis string `json:"synopsis"`
- Parent string `json:"parent,omitempty"`
+ Name string `json:"name"`
+ Kind string `json:"kind"`
+ Synopsis string `json:"synopsis"`
+ Parent string `json:"parent,omitempty"`
}

// SearchResults is the response for /v1/search?q={query}.
diff --git a/internal/api/api.go b/internal/api/api.go
index 95c898f..d7ff45b 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -372,20 +372,23 @@
var items []Symbol
for _, s := range syms {
items = append(items, Symbol{
- ModulePath: um.ModulePath,
- Version: um.Version,
- Name: s.Name,
- Kind: string(s.Kind),
- Synopsis: s.Synopsis,
- Parent: s.ParentName,
+ Name: s.Name,
+ Kind: string(s.Kind),
+ Synopsis: s.Synopsis,
+ Parent: s.ParentName,
})
}

- // api:response PaginatedResponse[Symbol]
- resp, err := paginate(items, params.ListParams, defaultLimit)
+ // api:response PackageSymbols
+ paged, err := paginate(items, params.ListParams, defaultLimit)
if err != nil {
return err
}
+ resp := PackageSymbols{
+ ModulePath: um.ModulePath,
+ Version: um.Version,
+ Symbols: paged,
+ }

return serveJSON(w, http.StatusOK, resp, versionCacheDur(params.Version))
}
diff --git a/internal/api/types.go b/internal/api/types.go
index 93c590f..e765a13 100644
--- a/internal/api/types.go
+++ b/internal/api/types.go
@@ -81,14 +81,19 @@
Contents string `json:"contents"`
}

-// Symbol is a symbol in /v1/symbols/{packagePath}.
+// PackageSymbols is the response for /v1/symbols/{packagePath}.
+type PackageSymbols struct {
+ ModulePath string `json:"modulePath"`
+ Version string `json:"version"`
+ Symbols PaginatedResponse[Symbol] `json:"symbols"`
+}
+
+// Symbol is a symbol in a package.
type Symbol struct {
- ModulePath string `json:"modulePath"`
- Version string `json:"version"`
- Name string `json:"name"`
- Kind string `json:"kind"`
- Synopsis string `json:"synopsis"`
- Parent string `json:"parent,omitempty"`
+ Name string `json:"name"`
+ Kind string `json:"kind"`
+ Synopsis string `json:"synopsis"`
+ Parent string `json:"parent,omitempty"`
}

// SearchResults is the response for /v1/search?q={query}.
diff --git a/internal/tests/api/api_test.go b/internal/tests/api/api_test.go
index c4d6f6a..7c7fd90 100644
--- a/internal/tests/api/api_test.go
+++ b/internal/tests/api/api_test.go
@@ -1174,12 +1174,12 @@
}

if test.wantStatus == http.StatusOK {
- var got api.PaginatedResponse[api.Symbol]
+ var got api.PackageSymbols
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
t.Fatalf("json.Unmarshal: %v", err)
}
var gotNames []string
- for _, it := range got.Items {
+ for _, it := range got.Symbols.Items {
gotNames = append(gotNames, it.Name)
}
slices.Sort(gotNames)

Change information

Files:
  • M cmd/internal/pkgsite-cli/client/client.go
  • M cmd/internal/pkgsite-cli/client/client_test.go
  • M cmd/internal/pkgsite-cli/client/types_gen.go
  • M internal/api/api.go
  • M internal/api/types.go
  • M internal/tests/api/api_test.go
Change size: M
Delta: 6 files changed, 50 insertions(+), 33 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
  • requirement is not satisfiedkokoro-CI-Passes
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I4c59cd2e387b53bb9bf00de1e1a8c14cc26c04e6
Gerrit-Change-Number: 771800
Gerrit-PatchSet: 1
Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

kokoro (Gerrit)

unread,
Apr 28, 2026, 7:26:42 PM (10 hours ago) Apr 28
to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Hyang-Ah Hana Kim

kokoro voted kokoro-CI+1

Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/5c62651b-8be3-47c4-aeda-d4fe5fd7ce1a

kokoro-CI+1
Open in Gerrit

Related details

Attention is currently required from:
  • Hyang-Ah Hana Kim
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    • requirement satisfiedkokoro-CI-Passes
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: pkgsite
    Gerrit-Branch: master
    Gerrit-Change-Id: I4c59cd2e387b53bb9bf00de1e1a8c14cc26c04e6
    Gerrit-Change-Number: 771800
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: kokoro <noreply...@google.com>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Comment-Date: Tue, 28 Apr 2026 23:26:38 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages