From 057677ab7f6a2d1db795818cc5dc5da9873945a7 Mon Sep 17 00:00:00 2001 From: Alex Dunmow Date: Fri, 10 Jul 2026 02:44:26 +0800 Subject: [PATCH] refactor: replace any with concrete types where shapes are known (check-safety 2e) Co-Authored-By: Claude Fable 5 --- block.go | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/block.go b/block.go index 593b07d..6889142 100644 --- a/block.go +++ b/block.go @@ -2,38 +2,41 @@ package main import ( "context" + "encoding/json" "fmt" "html" "strings" ) +type smartBlockGeneration struct { + ID string `json:"id"` + Template string `json:"template"` +} + +type smartBlockMeta struct { + Generations []smartBlockGeneration `json:"generations"` + CurrentGenerationID string `json:"currentGenerationId"` +} + // SmartBlockFunc renders a Smart Block by substituting {{field}} placeholders with content values. func SmartBlockFunc(ctx context.Context, content map[string]any) string { - // Get metadata - meta, ok := content["_meta"].(map[string]any) - if !ok { + rawMeta, err := json.Marshal(content["_meta"]) + if err != nil { + return renderEmptyState() + } + var meta smartBlockMeta + if err := json.Unmarshal(rawMeta, &meta); err != nil { return renderEmptyState() } - generations, ok := meta["generations"].([]any) - if !ok || len(generations) == 0 { + if len(meta.Generations) == 0 || meta.CurrentGenerationID == "" { return renderEmptyState() } - currentID, _ := meta["currentGenerationId"].(string) - if currentID == "" { - return renderEmptyState() - } - - // Find the current generation var template string - for _, gen := range generations { - genMap, ok := gen.(map[string]any) - if !ok { - continue - } - if genMap["id"] == currentID { - template, _ = genMap["template"].(string) + for _, gen := range meta.Generations { + if gen.ID == meta.CurrentGenerationID { + template = gen.Template break } }