aboutsummaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2026-03-18 13:27:53 -0400
committerJonathan Amsterdam <jba@google.com>2026-03-18 12:14:22 -0700
commit71f5bef85c18c92a4652faea046caaadbb0d4969 (patch)
tree5e0250ea115acfa2af34b12bdb52a513f82cff24 /internal/api
parent9b7f749dab1cca49376cabf86673e35a3faff8fb (diff)
downloadgo-x-pkgsite-71f5bef85c18c92a4652faea046caaadbb0d4969.tar.xz
internal/api: tweaks
- Minor doc changes. - Slight code reorg. - Use new reflect.Pointer over reflect.Ptr. Change-Id: If1a6bb1d335f32a119cc8b4487e3eacbcd6b6431 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/756420 Reviewed-by: Ethan Lee <ethanalee@google.com> kokoro-CI: kokoro <noreply+kokoro@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/params.go34
-rw-r--r--internal/api/types.go18
2 files changed, 26 insertions, 26 deletions
diff --git a/internal/api/params.go b/internal/api/params.go
index cdc5f4c5..9b01e7be 100644
--- a/internal/api/params.go
+++ b/internal/api/params.go
@@ -18,7 +18,7 @@ type ListParams struct {
Filter string `form:"filter"`
}
-// PackageParams represents query parameters for /v1/package/{path}.
+// PackageParams are query parameters for /v1/package/{path}.
type PackageParams struct {
Module string `form:"module"`
Version string `form:"version"`
@@ -29,7 +29,7 @@ type PackageParams struct {
Licenses bool `form:"licenses"`
}
-// SymbolsParams represents query parameters for /v1/symbols/{path}.
+// SymbolsParams are query parameters for /v1/symbols/{path}.
type SymbolsParams struct {
Module string `form:"module"`
Version string `form:"version"`
@@ -39,39 +39,39 @@ type SymbolsParams struct {
Examples bool `form:"examples"`
}
-// ImportedByParams represents query parameters for /v1/imported-by/{path}.
+// ImportedByParams are query parameters for /v1/imported-by/{path}.
type ImportedByParams struct {
Module string `form:"module"`
Version string `form:"version"`
ListParams
}
-// ModuleParams represents query parameters for /v1/module/{path}.
+// ModuleParams are query parameters for /v1/module/{path}.
type ModuleParams struct {
Version string `form:"version"`
Licenses bool `form:"licenses"`
Readme bool `form:"readme"`
}
-// VersionsParams represents query parameters for /v1/versions/{path}.
+// VersionsParams are query parameters for /v1/versions/{path}.
type VersionsParams struct {
ListParams
}
-// PackagesParams represents query parameters for /v1/packages/{path}.
+// PackagesParams are query parameters for /v1/packages/{path}.
type PackagesParams struct {
Version string `form:"version"`
ListParams
}
-// SearchParams represents query parameters for /v1/search.
+// SearchParams are query parameters for /v1/search.
type SearchParams struct {
Query string `form:"q"`
Symbol string `form:"symbol"`
ListParams
}
-// VulnParams represents query parameters for /v1/vulns/{module}.
+// VulnParams are query parameters for /v1/vulns/{module}.
type VulnParams struct {
Version string `form:"version"`
ListParams
@@ -79,10 +79,10 @@ type VulnParams struct {
// ParseParams populates a struct from url.Values using 'form' tags.
// dst must be a pointer to a struct. It supports embedded structs recursively,
-// pointers, slices, and basic types (string, int, int64, bool).
+// pointers, slices, and basic types (string, bool, int types).
func ParseParams(v url.Values, dst any) error {
val := reflect.ValueOf(dst)
- if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct {
+ if val.Kind() != reflect.Pointer || val.Elem().Kind() != reflect.Struct {
return fmt.Errorf("dst must be a pointer to a struct")
}
return parseValue(v, val.Elem())
@@ -100,7 +100,7 @@ func parseValue(v url.Values, val reflect.Value) error {
if structField.Anonymous {
f := field
- if f.Kind() == reflect.Ptr {
+ if f.Kind() == reflect.Pointer {
if f.IsNil() {
if !f.CanSet() {
continue
@@ -153,13 +153,13 @@ func setField(field reflect.Value, tag string, vals []string) error {
}
func setAny(field reflect.Value, tag, val string) error {
- if field.Kind() == reflect.Ptr {
- if field.IsNil() {
- field.Set(reflect.New(field.Type().Elem()))
- }
- return setAny(field.Elem(), tag, val)
+ if field.Kind() != reflect.Pointer {
+ return setSingle(field, tag, val)
+ }
+ if field.IsNil() {
+ field.Set(reflect.New(field.Type().Elem()))
}
- return setSingle(field, tag, val)
+ return setAny(field.Elem(), tag, val)
}
func setSingle(field reflect.Value, tag, val string) error {
diff --git a/internal/api/types.go b/internal/api/types.go
index 8b6e4941..92569ab1 100644
--- a/internal/api/types.go
+++ b/internal/api/types.go
@@ -4,7 +4,7 @@
package api
-// Package represents the response for /v1/package/{packagePath}.
+// Package is the response for /v1/package/{packagePath}.
type Package struct {
Path string `json:"path"`
ModulePath string `json:"modulePath"`
@@ -19,7 +19,7 @@ type Package struct {
Licenses []License `json:"licenses,omitempty"`
}
-// License represents license information in API responses.
+// License is license information in API responses.
type License struct {
Types []string `json:"types"`
FilePath string `json:"filePath"`
@@ -33,14 +33,14 @@ type PaginatedResponse[T any] struct {
NextPageToken string `json:"nextPageToken,omitempty"`
}
-// PackageImportedBy represents the response for /v1/imported-by/{packagePath}.
+// PackageImportedBy is the response for /v1/imported-by/{packagePath}.
type PackageImportedBy struct {
ModulePath string `json:"modulePath"`
Version string `json:"version"`
ImportedBy PaginatedResponse[string] `json:"importedBy"`
}
-// Module represents the response for /v1/module/{modulePath}.
+// Module is the response for /v1/module/{modulePath}.
type Module struct {
Path string `json:"path"`
Version string `json:"version"`
@@ -53,13 +53,13 @@ type Module struct {
Licenses []License `json:"licenses,omitempty"`
}
-// Readme represents a readme file.
+// Readme is a readme file.
type Readme struct {
Filepath string `json:"filepath"`
Contents string `json:"contents"`
}
-// Symbol represents a symbol in /v1/symbols/{packagePath}.
+// Symbol is a symbol in /v1/symbols/{packagePath}.
type Symbol struct {
ModulePath string `json:"modulePath"`
Version string `json:"version"`
@@ -69,7 +69,7 @@ type Symbol struct {
Parent string `json:"parent,omitempty"`
}
-// SearchResults represents the response for /v1/search?q={query}.
+// SearchResults is the response for /v1/search?q={query}.
type SearchResult struct {
PackagePath string `json:"packagePath"`
ModulePath string `json:"modulePath"`
@@ -77,7 +77,7 @@ type SearchResult struct {
Synopsis string `json:"synopsis"`
}
-// Vulnerability represents a vulnerability in /v1/vulnerabilities/{modulePath}.
+// Vulnerability is a vulnerability in /v1/vulnerabilities/{modulePath}.
type Vulnerability struct {
ID string `json:"id"`
Summary string `json:"summary"`
@@ -92,7 +92,7 @@ type Error struct {
Candidates []Candidate `json:"candidates,omitempty"`
}
-// Candidate represents a potential resolution for an ambiguous path.
+// Candidate is a potential resolution for an ambiguous path.
type Candidate struct {
ModulePath string `json:"modulePath"`
PackagePath string `json:"packagePath"`