validate

package
v0.99.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package validate provides shared validation rules and helpers for the application.

Index

Constants

View Source
const (
	// Text field limits
	TitleMaxLen = 200
	DescMaxLen  = 2000
	NameMaxLen  = 100

	// URL limits
	URLMaxLen = 2048

	// Tag limits
	TagMaxLen    = 50
	MaxTagsCount = 50
	MinTagLen    = 1

	// Query limits
	QueryMaxLen = 100
	// CursorMaxLen is the max length for opaque pagination cursors (HMAC-signed
	// EncodeCursor tokens). Distinct from QueryMaxLen — search text stays short;
	// cursors routinely exceed 100 characters.
	CursorMaxLen   = 4096
	MaxSearchLimit = 100

	// File upload limits
	MaxFileSizeMB    = 10
	MaxFileSizeBytes = MaxFileSizeMB * 1024 * 1024
	MaxFileCount     = 10
)

Common validation constants

View Source
const (
	// Required title: non-empty, max 200 chars
	TagTitle = "required,min=1,max=200"

	// Optional title: if provided, max 200 chars
	TagTitleOptional = "omitempty,min=1,max=200"

	// Required description: non-empty, max 2000 chars
	TagDescription = "required,min=1,max=2000"

	// Optional description: if provided, max 2000 chars
	TagDescriptionOptional = "omitempty,max=2000"

	// Required URL: valid URL format, max 2048 chars
	TagURL = "required,url,max=2048"

	// Optional URL: if provided, valid URL format
	TagURLOptional = "omitempty,url,max=2048"

	// Positive integer ID (for IDs that must be > 0)
	TagID = "required,gte=1"

	// Optional positive integer ID
	TagIDOptional = "omitempty,gte=1"

	// Non-negative integer
	TagNonNegative = "gte=0"

	// Required non-empty string
	TagRequired = "required,min=1"

	// Tag list: required, each tag 1-50 chars, max 50 tags
	TagList = "required,dive,min=1,max=50"
)

Common validation tags for reuse in struct definitions

View Source
const (
	SkillNameMaxLen          = 64
	SkillDescMaxLen          = 1024
	SkillCompatibilityMaxLen = 500
)

Agent Skills limits from https://agentskills.io/specification (skills-ref).

Variables

View Source
var Validate = validator.New()

Validate is the global validator instance

Functions

func IsListTool

func IsListTool(group, op string) bool

IsListTool reports whether group.op is a paged list. Capability operations match when the name contains "list". Pipeline, workflow, and function list, plus hub apps, are paged too.

func SkillCompatibility

func SkillCompatibility(compatibility string) error

SkillCompatibility checks an optional compatibility field (≤ SkillCompatibilityMaxLen runes).

func SkillDescription

func SkillDescription(description string) error

SkillDescription checks a skill description (required, ≤ SkillDescMaxLen runes).

func SkillDocument

func SkillDocument(name, description, compatibility, dirName string) error

SkillDocument checks Agent Skills identity fields including optional compatibility.

func SkillIdentity

func SkillIdentity(name, description, dirName string) error

SkillIdentity checks name, description, and optional directory match together.

func SkillName

func SkillName(name string) error

SkillName checks a skill name against the Agent Skills naming rules.

Rules: 1–64 characters; lowercase letters, digits, and hyphens only; must not start or end with a hyphen; must not contain consecutive hyphens.

func SkillNameMatchesDir

func SkillNameMatchesDir(name, dirName string) error

SkillNameMatchesDir reports whether name equals the skill directory basename. dirName of "" or "." skips the check (root-level SKILL.md imports).

func ValidateVar

func ValidateVar(v any, tag string) error

ValidateVar validates a single variable against a tag

Types

type SkillFrontmatter

type SkillFrontmatter struct {
	Name          string `yaml:"name"`
	Description   string `yaml:"description"`
	Compatibility string `yaml:"compatibility"`
}

SkillFrontmatter is the YAML header of a SKILL.md file.

func ParseSkillMarkdown

func ParseSkillMarkdown(raw string) (SkillFrontmatter, string, error)

ParseSkillMarkdown splits SKILL.md into YAML frontmatter and markdown body.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL