[pkgsite] internal/api, internal/postgres: flatten symbols and support kind filtering

1 view
Skip to first unread message

Ethan Lee (Gerrit)

unread,
May 18, 2026, 6:17:35 PM (14 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ethan Lee has uploaded the change for review

Commit message

internal/api, internal/postgres: flatten symbols and support kind filtering

Flatten the package symbols list returned by the database (GetSymbols)
instead of nesting them under 'Children', allowing all symbols (including
type methods, fields, and constructors) to be returned as flat items in
the 'symbols' API response.

To support this flatter structure, we:
- Leverage the existing 'parent' reference field in 'api.Symbol' to
point parented symbols (methods, fields) to their containing types.
- Add a 'kind' query parameter to '/v1beta/symbols/{path}' to allow
clients to explicitly filter symbols by their kind (constant,
variable, function, type, field, or method) case-insensitively.
- Update the 'filter' query parameter to also search the symbol kind.
Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025

Change diff

diff --git a/internal/api/api.go b/internal/api/api.go
index 4fc8658..ea34423 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -424,8 +424,14 @@
return fmt.Errorf("symbols for package %s: %w", pkgPath, err)
}

+ if params.Kind != "" {
+ syms = slices.DeleteFunc(syms, func(s *internal.Symbol) bool {
+ return !strings.EqualFold(string(s.Kind), params.Kind)
+ })
+ }
+
syms, err = filter(syms, params.Filter, func(s *internal.Symbol) []string {
- return []string{s.Name, s.Synopsis}
+ return []string{s.Name, s.Synopsis, string(s.Kind)}
})
if err != nil {
return err
diff --git a/internal/api/openapi.yaml b/internal/api/openapi.yaml
index ce61165..fb0cdaf 100644
--- a/internal/api/openapi.yaml
+++ b/internal/api/openapi.yaml
@@ -348,6 +348,14 @@
}
},
{
+ "description": "include only symbols of this kind",
+ "in": "query",
+ "name": "kind",
+ "schema": {
+ "type": "string"
+ }
+ },
+ {
"description": "max number of items to return",
"in": "query",
"name": "limit",
diff --git a/internal/api/params.go b/internal/api/params.go
index 1119b11..cee9ab4 100644
--- a/internal/api/params.go
+++ b/internal/api/params.go
@@ -52,6 +52,8 @@
GOOS string `form:"goos"`
// GOARCH of documentation build context
GOARCH string `form:"goarch"`
+ // include only symbols of this kind
+ Kind string `form:"kind"`
ListParams
}

diff --git a/internal/postgres/package_symbol.go b/internal/postgres/package_symbol.go
index 5325e61..f1159cb 100644
--- a/internal/postgres/package_symbol.go
+++ b/internal/postgres/package_symbol.go
@@ -63,12 +63,6 @@
Kind: kind,
Synopsis: synopsis,
}
- if sm.ParentName != "" && sm.ParentName != sm.Name {
- if parent, ok := symbolMap[sm.ParentName]; ok {
- parent.Children = append(parent.Children, &sm)
- return nil
- }
- }
// Treat as top-level if no parent or parent not found in this build context.
s := &internal.Symbol{
SymbolMeta: sm,
diff --git a/internal/tests/api/api_test.go b/internal/tests/api/api_test.go
index 2b02e7e..134ac68 100644
--- a/internal/tests/api/api_test.go
+++ b/internal/tests/api/api_test.go
@@ -1062,11 +1062,11 @@

func testServePackageSymbols(t *testing.T, ds internal.TestingDataSource) {

- sym := func(doc *internal.Documentation, name string) *internal.Symbol {
+ sym := func(doc *internal.Documentation, name string, kind internal.SymbolKind) *internal.Symbol {
return &internal.Symbol{
SymbolMeta: internal.SymbolMeta{
Name: name,
- Kind: internal.SymbolKindFunction,
+ Kind: kind,
Section: internal.SymbolSectionFunctions,
},
GOOS: doc.GOOS,
@@ -1075,11 +1075,15 @@
}

linuxDoc := sample.Documentation("linux", "amd64", sample.DocContents)
- linuxDoc.API = []*internal.Symbol{sym(linuxDoc, "LinuxSym"), sym(linuxDoc, "F")}
+ linuxDoc.API = []*internal.Symbol{
+ sym(linuxDoc, "LinuxSym", internal.SymbolKindFunction),
+ sym(linuxDoc, "F", internal.SymbolKindFunction),
+ sym(linuxDoc, "LinuxType", internal.SymbolKindType),
+ }
winDoc := sample.Documentation("windows", "amd64", sample.DocContents)
- winDoc.API = []*internal.Symbol{sym(winDoc, "WindowsSym")}
+ winDoc.API = []*internal.Symbol{sym(winDoc, "WindowsSym", internal.SymbolKindFunction)}
wasmDoc := sample.Documentation("js", "wasm", sample.DocContents)
- wasmDoc.API = []*internal.Symbol{sym(wasmDoc, "WasmSym")}
+ wasmDoc.API = []*internal.Symbol{sym(wasmDoc, "WasmSym", internal.SymbolKindFunction)}
ds.MustInsertModule(t,
module(t, modinfo("example.com", "v1.0.0"),
unit("pkg", linuxDoc, winDoc, wasmDoc)))
@@ -1095,7 +1099,7 @@
name: "default best match (linux)",
url: "/v1beta/symbols/example.com/pkg?version=v1.0.0",
wantStatus: http.StatusOK,
- wantNames: []string{"F", "LinuxSym"},
+ wantNames: []string{"F", "LinuxSym", "LinuxType"},
},
{
name: "package not found",
@@ -1113,13 +1117,13 @@
name: "explicit linux",
url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&goos=linux&goarch=amd64",
wantStatus: http.StatusOK,
- wantNames: []string{"F", "LinuxSym"},
+ wantNames: []string{"F", "LinuxSym", "LinuxType"},
},
{
name: "version latest",
url: "/v1beta/symbols/example.com/pkg?version=latest",
wantStatus: http.StatusOK,
- wantNames: []string{"F", "LinuxSym"},
+ wantNames: []string{"F", "LinuxSym", "LinuxType"},
},
{
name: "explicit windows",
@@ -1142,6 +1146,24 @@
Message: "not found",
},
},
+ {
+ name: "kind filter (function)",
+ url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&kind=function",
+ wantStatus: http.StatusOK,
+ wantNames: []string{"F", "LinuxSym"},
+ },
+ {
+ name: "kind filter (type)",
+ url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&kind=type",
+ wantStatus: http.StatusOK,
+ wantNames: []string{"LinuxType"},
+ },
+ {
+ name: "kind filter (type, case insensitive)",
+ url: "/v1beta/symbols/example.com/pkg?version=v1.0.0&kind=Type",
+ wantStatus: http.StatusOK,
+ wantNames: []string{"LinuxType"},
+ },
} {
t.Run(test.name, func(t *testing.T) {
r := httptest.NewRequest("GET", test.url, nil)

Change information

Files:
  • M internal/api/api.go
  • M internal/api/openapi.yaml
  • M internal/api/params.go
  • M internal/postgres/package_symbol.go
  • M internal/tests/api/api_test.go
Change size: M
Delta: 5 files changed, 47 insertions(+), 15 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: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 1
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
May 18, 2026, 10:28:11 PM (10 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
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: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 2
Gerrit-Owner: Ethan Lee <etha...@google.com>
Gerrit-Reviewer: Ethan Lee <etha...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
May 18, 2026, 10:29:14 PM (10 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #3 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
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: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 3
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
May 18, 2026, 10:37:22 PM (10 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #4 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
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: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 4
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
May 18, 2026, 10:39:37 PM (9 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #5 to this change.
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
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: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 5
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
May 18, 2026, 10:43:31 PM (9 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #6 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
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: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 6
unsatisfied_requirement
satisfied_requirement
open
diffy

Ethan Lee (Gerrit)

unread,
May 18, 2026, 11:14:43 PM (9 hours ago) May 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Ethan Lee

Ethan Lee uploaded new patchset

Ethan Lee uploaded patch set #7 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
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: newpatchset
Gerrit-Project: pkgsite
Gerrit-Branch: master
Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
Gerrit-Change-Number: 779441
Gerrit-PatchSet: 7
unsatisfied_requirement
satisfied_requirement
open
diffy

kokoro (Gerrit)

unread,
May 18, 2026, 11:41:02 PM (8 hours ago) May 18
to Ethan Lee, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Jonathan Amsterdam, Hyang-Ah Hana Kim, golang-co...@googlegroups.com
Attention needed from Ethan Lee, Hyang-Ah Hana Kim and Jonathan Amsterdam

kokoro voted kokoro-CI+1

Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/08d5410c-0830-4929-aebe-195b84641830

kokoro-CI+1
Open in Gerrit

Related details

Attention is currently required from:
  • Ethan Lee
  • Hyang-Ah Hana Kim
  • Jonathan Amsterdam
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: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
    Gerrit-Change-Number: 779441
    Gerrit-PatchSet: 7
    Gerrit-Owner: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Ethan Lee <etha...@google.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: kokoro <noreply...@google.com>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
    Gerrit-Attention: Ethan Lee <etha...@google.com>
    Gerrit-Comment-Date: Tue, 19 May 2026 03:40:57 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Ethan Lee (Gerrit)

    unread,
    May 18, 2026, 11:50:06 PM (8 hours ago) May 18
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Ethan Lee, Hyang-Ah Hana Kim and Jonathan Amsterdam

    Ethan Lee uploaded new patchset

    Ethan Lee uploaded patch set #8 to this change.
    Following approvals got outdated and were removed:
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Ethan Lee
    • Hyang-Ah Hana Kim
    • Jonathan Amsterdam
    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: newpatchset
      Gerrit-Project: pkgsite
      Gerrit-Branch: master
      Gerrit-Change-Id: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
      Gerrit-Change-Number: 779441
      Gerrit-PatchSet: 8
      unsatisfied_requirement
      satisfied_requirement
      open
      diffy

      kokoro (Gerrit)

      unread,
      12:15 AM (8 hours ago) 12:15 AM
      to Ethan Lee, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Jonathan Amsterdam, Hyang-Ah Hana Kim, golang-co...@googlegroups.com
      Attention needed from Ethan Lee, Hyang-Ah Hana Kim and Jonathan Amsterdam

      kokoro voted kokoro-CI+1

      Kokoro presubmit build finished with status: SUCCESS

      Related details

      Attention is currently required from:
      • Ethan Lee
      • Hyang-Ah Hana Kim
      • Jonathan Amsterdam
      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: I71af9051b8e7f94a40fb24aa4b46dd32a4c50025
        Gerrit-Change-Number: 779441
        Gerrit-PatchSet: 8
        Gerrit-Owner: Ethan Lee <etha...@google.com>
        Gerrit-Reviewer: Ethan Lee <etha...@google.com>
        Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
        Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
        Gerrit-Reviewer: kokoro <noreply...@google.com>
        Gerrit-CC: kokoro <noreply...@google.com>
        Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
        Gerrit-Attention: Jonathan Amsterdam <j...@google.com>
        Gerrit-Attention: Ethan Lee <etha...@google.com>
        Gerrit-Comment-Date: Tue, 19 May 2026 04:15:13 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages