add routes for block, validate block slug

This commit is contained in:
2026-02-12 23:12:30 +00:00
parent cb0d6c1d3a
commit b68ab8bc23
5 changed files with 60 additions and 4 deletions

View File

@@ -2,12 +2,24 @@ package block
import (
"encoding/json"
"fmt"
"regexp"
)
var validSlug = regexp.MustCompile(`^[a-z0-9]+$`)
type Block struct {
Slug string
Components []Component
}
func NewBlock(slug string, components []Component) (*Block, error) {
if !validSlug.MatchString(slug) {
return nil, fmt.Errorf("invalid block slug %q: must be a-z0-9 only", slug)
}
return &Block{Slug: slug, Components: components}, nil
}
type BlockInstance struct {
Components []ComponentInstance
}