add routes for block, validate block slug
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user