value-object-go

Create immutable value objects in Go with validated constructors and accessor methods.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill value-object-go-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: value-object-go
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/value-object/go
Command: npx skills add https://github.com/gabriellst/codm --skill value-object-go-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires go-playground/validator.

What problem does it solve? Domain concepts like Email, CPF, or Address need validation and immutability guarantees, but plain Go structs with public fields allow invalid states and uncontrolled mutation. This Skill provides a consistent pattern for modeling value objects that validate themselves at construction and can never be tampered with afterward. ## Core Features & Use Cases - Primitive Value Objects: Wrap single values like Email, CPF, or JobOutputUrl with private fields, a New<Name> constructor returning (T, error), and the accessor quartet Value(), String(), Equals(), IsZero(). - Composite Value Objects: Model multi-field concepts like Address or Money using validate struct tags with go-playground/validator via validation.ValidateWithCode. - Typed Error Handling: Constructors return errors.NewBaseError(code, message) so HTTP mappers translate failures to correct status codes, never panicking. - Use Case: When adding a JobOutputUrl field to a transcoding entity, generate a context-specific VO in internal/transcoding/objects/ that validates the URL format at construction and rejects empty or malformed values. ## Quick Start Create a Go value object for Email with a validating constructor, private fields, and Value, String, Equals, and IsZero methods.

Frequently Asked Questions about value-object-go

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an immutable value object in Go?

Declare a struct with only private (lowercase) fields and expose read access through exported accessor methods like Value() and String(). Provide a New<Name> constructor that validates input and returns (T, error), never a pointer or panic.

How to validate struct fields in Go with go-playground/validator?

Add validate struct tags such as `validate:"required"` or `validate:"len=2"` to private fields, then call validation.ValidateWithCode(&v, code) inside the constructor. This keeps constraints co-located with field declarations instead of manual if-chains.

Should a Go value object constructor return a pointer or a value?

Return the value type, not a pointer. On validation failure return the zero value (e.g., Email{}) alongside the error, since returning nil is only valid for pointer types and value semantics reinforce immutability.

When should I not use a value object pattern in Go?

Skip the VO pattern for simple strings with no validation or domain behavior, for values needing identity across time (use an entity), and for large data bags without invariants where a plain struct suffices.

Why does my value object need an IsZero method?

IsZero lets repositories and use cases distinguish a field that was never set from one set to empty. Omitting it causes nil-check bugs when VOs appear as optional fields on entities.