From 6db5e7e44c437a04ce4c5193d7fa3399d31131da Mon Sep 17 00:00:00 2001 From: Bretton Date: Thu, 6 Nov 2025 15:49:35 -0800 Subject: [PATCH] docs(utils): enhance ExtractCollectionFromURI documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add comprehensive documentation explaining return value semantics for malformed URIs. Changes: - Clarify that empty string indicates "unknown/unsupported collection" - Document that callers should validate return value before using for DB queries - Add examples of expected collection names (e.g., "social.coves.feed.comment") - Explain format expectations (at://did/collection/rkey) This addresses PR review feedback about input validation documentation. Empty string is the correct sentinel value indicating unparseable/invalid URIs, and callers must handle this appropriately. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/atproto/utils/record_utils.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/atproto/utils/record_utils.go b/internal/atproto/utils/record_utils.go index 69b1990..6834255 100644 --- a/internal/atproto/utils/record_utils.go +++ b/internal/atproto/utils/record_utils.go @@ -16,6 +16,25 @@ func ExtractRKeyFromURI(uri string) string { return "" } +// ExtractCollectionFromURI extracts the collection from an AT-URI +// Format: at://did/collection/rkey -> collection +// +// Returns: +// - Collection name (e.g., "social.coves.feed.comment") if URI is well-formed +// - Empty string if URI is malformed or doesn't contain a collection segment +// +// Note: Empty string indicates "unknown/unsupported collection" and should be +// handled as an invalid or unparseable URI by the caller. Callers should validate +// the return value before using it for database queries or business logic. +func ExtractCollectionFromURI(uri string) string { + withoutScheme := strings.TrimPrefix(uri, "at://") + parts := strings.Split(withoutScheme, "/") + if len(parts) >= 2 { + return parts[1] + } + return "" +} + // StringFromNull converts sql.NullString to string // Returns empty string if the NullString is not valid func StringFromNull(ns sql.NullString) string { -- 2.54.0