validation

package
v0.0.155 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: 0BSD Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldUserName       = "user_name"
	FieldAppName        = "app_name"
	FieldVersionName    = "version_name"
	FieldSearchTerm     = "search_term"
	FieldPassword       = "password"
	FieldEmail          = "email"
	FieldNumber         = "number"
	FieldHost           = "host"
	FieldKnownHosts     = "known_hosts"
	FieldResticBackupID = "restic_backup_id"
	FieldRemoteHost     = "remote_host"
	FieldEmailOrEmpty   = "email_or_empty"
	FieldSecret         = "secret"
	FieldType           = "type"
)

Variables

View Source
var ValidationMap = map[string]Regex{
	FieldUserName:       NewSimpleRegex("a-z0-9", 3, 20),
	FieldAppName:        NewSimpleRegex("a-z0-9", 3, 20),
	FieldVersionName:    NewSimpleRegex("a-z0-9.", 3, 20),
	FieldSearchTerm:     NewSimpleRegex("a-z0-9", 0, 20),
	FieldPassword:       NewSimpleRegex("a-zA-Z0-9._-", 8, 30),
	FieldEmail:          NewGenericRegex(emailRegex),
	FieldNumber:         NewSimpleRegex("0-9", 1, 20),
	FieldHost:           NewSimpleRegex("a-zA-Z0-9:._-", 0, 64),
	FieldKnownHosts:     NewGenericRegex(`^[A-Za-z0-9.:,/_+=#@\[\]| \r\n-]{0,}$`),
	FieldResticBackupID: NewSimpleRegex("a-f0-9", 64, 64),
	FieldRemoteHost:     NewSimpleRegex("a-zA-Z0-9._-", 0, 64),
	FieldEmailOrEmpty:   NewGenericRegex(`^$|^` + emailRegexSuffix),
	FieldSecret:         simpleSecretRegex,
}

Functions

func AssertYamlEquality

func AssertYamlEquality(t *testing.T, a, b []byte)

func CompleteDockerComposeYaml

func CompleteDockerComposeYaml(maintainer, appName, filePath, host string) error

func ReadBody added in v0.0.77

func ReadBody[T any](w http.ResponseWriter, r *http.Request) (*T, bool)

func Validate added in v0.0.77

func Validate(validationTag, fieldValue string) error

func ValidateStruct added in v0.0.78

func ValidateStruct(inputStructure any) error

func ValidateVersion

func ValidateVersion(zipBytes []byte, maintainerName, appName string) error

func ZipDirectory

func ZipDirectory(dirPath string) ([]byte, error)

Types

type GenericRegex added in v0.0.151

type GenericRegex struct {
	RegexString string
	Regex       *regexp.Regexp
}

func NewGenericRegex added in v0.0.151

func NewGenericRegex(regexString string) *GenericRegex

func (*GenericRegex) MatchString added in v0.0.151

func (r *GenericRegex) MatchString(fieldName, input string) error

type Regex added in v0.0.151

type Regex interface {
	MatchString(string, string) error
}

type SimpleRegex added in v0.0.151

type SimpleRegex struct {
	AllowedSymbols string
	MinLength      int
	MaxLength      int
	Regex          *regexp.Regexp
}

func NewSimpleRegex added in v0.0.151

func NewSimpleRegex(allowedSymbols string, minLength, maxLength int) *SimpleRegex

func (*SimpleRegex) MatchString added in v0.0.151

func (r *SimpleRegex) MatchString(fieldName, input string) error

Jump to

Keyboard shortcuts

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