Help us shape the future of Go! Take the 2026 Go Developer Survey

validators

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package validators contains entity validation logic

Package validators contains entity validation logic

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPrivateRepoForbidden is returned when a private repository is not allowed
	ErrPrivateRepoForbidden = util.UserVisibleError(codes.InvalidArgument, "private repositories are not allowed in this project")
	// ErrArchivedRepoForbidden is returned when an archived repository cannot be registered
	ErrArchivedRepoForbidden = util.UserVisibleError(codes.InvalidArgument, "archived repositories cannot be registered")
)

Functions

This section is empty.

Types

type RepositoryValidator

type RepositoryValidator struct {
	// contains filtered or unexported fields
}

RepositoryValidator validates repository entity creation. This validator should be registered for ENTITY_REPOSITORIES using the ValidatorRegistry.AddValidator method.

func NewRepositoryValidator

func NewRepositoryValidator(store db.Store) *RepositoryValidator

NewRepositoryValidator creates a new RepositoryValidator

func (*RepositoryValidator) Validate

func (v *RepositoryValidator) Validate(
	ctx context.Context,
	props *properties.Properties,
	projectID uuid.UUID,
) error

Validate checks if a repository entity can be created. This validator is called only for repositories since it's registered specifically for that entity type via the ValidatorRegistry.

type Validator

type Validator interface {
	// Validate returns nil if entity is valid, error otherwise.
	Validate(
		ctx context.Context,
		props *properties.Properties,
		projectID uuid.UUID,
	) error
}

Validator validates an entity of a specific type. Unlike a general validator, this does NOT receive entityType since validators are registered for specific entity types.

type ValidatorHandle

type ValidatorHandle struct {
	// contains filtered or unexported fields
}

ValidatorHandle is an opaque handle returned when registering a validator. It can be used to remove the validator later.

type ValidatorRegistry

type ValidatorRegistry interface {
	// AddValidator registers a validator for a specific entity type.
	// Returns a handle that can be used to remove the validator.
	AddValidator(entityType pb.Entity, validator Validator) ValidatorHandle

	// RemoveValidator removes a previously registered validator.
	RemoveValidator(handle ValidatorHandle)

	// Validate runs all validators registered for the given entity type.
	// Returns nil if no validators are registered (validation is optional).
	// Returns the first validation error encountered.
	Validate(
		ctx context.Context,
		entityType pb.Entity,
		props *properties.Properties,
		projectID uuid.UUID,
	) error

	// HasValidators returns true if at least one validator is registered
	// for the given entity type.
	HasValidators(entityType pb.Entity) bool
}

ValidatorRegistry manages entity validators by entity type. Validators register for specific entity types and are called when entities of that type are created.

func NewValidatorRegistry

func NewValidatorRegistry() ValidatorRegistry

NewValidatorRegistry creates a new validator registry.

Jump to

Keyboard shortcuts

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