model

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package model provides data structures and validation logic for the dehydrated-api-go application. It includes domain entry models, request/response structures, and protobuf conversion utilities.

Index

Constants

View Source
const (
	DefaultPerPage = 100
	MaxPerPage     = 1000
	MinPerPage     = 1
	MinPage        = 1
)

Pagination constants

Variables

This section is empty.

Functions

func IsValidDomain

func IsValidDomain(domain string) bool

IsValidDomain checks if a string is a valid domain name or wildcard domain. It validates the domain against a regular expression that enforces the following rules: - Domain parts can contain letters, numbers, and hyphens - Hyphens cannot be at the start or end of a part - At least one dot is required (except for wildcard domains) - Optional wildcard at the start of the first part - TLD must be at least 2 characters Returns true if the domain is valid, false otherwise.

func IsValidDomainEntry

func IsValidDomainEntry(entry *DomainEntry) bool

IsValidDomainEntry checks if a DomainEntry is valid by validating its domain field. It ensures that the domain name follows the standard domain naming conventions. Returns true if the domain entry is valid, false otherwise.

Types

type ConfigResponse added in v0.2.0

type ConfigResponse struct {
	Success bool `json:"success" example:"true"`

	Data *dehydrated.Config `json:"data,omitempty"`

	Error string `json:"error,omitempty" example:"Failed to load config"`
}

type CreateDomainRequest

type CreateDomainRequest struct {
	// Domain is the primary domain name (required).
	// @Description Primary domain name (required)
	// @required
	Domain string `json:"domain" validate:"required" example:"example.com"`

	// AlternativeNames is a list of additional domain names.
	// @Description List of additional domain names (e.g., "www.example.com")
	AlternativeNames []string `json:"alternative_names,omitempty" example:"www.example.com,api.example.com"`

	// Alias is an optional alternative identifier.
	// @Description Optional alternative identifier for the domain
	Alias string `json:"alias,omitempty" example:"my-domain"`

	// Enabled indicates whether the domain should be active.
	// @Description Whether the domain is enabled for certificate issuance
	Enabled bool `json:"enabled" example:"true"`

	// Comment is an optional description.
	// @Description Optional description or comment for the domain
	Comment string `json:"comment,omitempty" example:"Production domain for web application"`
}

CreateDomainRequest represents a request to create a new domain entry. It contains all the necessary fields to create a new domain configuration. @Description Request to create a new domain entry

type DeleteDomainRequest added in v0.2.0

type DeleteDomainRequest struct {
	// Alias is an optional alternative identifier.
	// @Description Optional alternative identifier for the domain
	Alias *string `json:"alias,omitempty" example:"my-domain"`
}

DeleteDomainRequest represents a request to delete an existing domain entry. An optional alias can be provided to uniquely identify the domain entry. @Description Request to delete an existing domain entry

type DomainEntries added in v0.2.0

type DomainEntries []*DomainEntry

DomainEntries is a slice of DomainEntry pointers that provides convenient methods for manipulation.

func (DomainEntries) Sort added in v0.2.0

func (e DomainEntries) Sort()

Sort sorts the domain entries alphabetically by domain name. Entries for the same domain are grouped together, with non-aliased entries first, followed by aliased entries for that domain. The sorting considers only the domain name and alias, ignoring alternative names and comments. This method modifies the slice in-place.

type DomainEntry

type DomainEntry struct {
	pb.DomainEntry

	// Metadata contains additional information about the domain entry.
	// @Description Additional metadata about the domain entry
	Metadata *pb.Metadata `json:"metadata,omitempty"`
}

DomainEntry represents a domain configuration entry in the dehydrated system. It contains all the necessary information for managing a domain's SSL certificate. @Description Domain configuration entry for SSL certificate management

func (*DomainEntry) Equals added in v0.2.0

func (e *DomainEntry) Equals(entry *DomainEntry) bool

func (*DomainEntry) MarshalJSON

func (e *DomainEntry) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface to ensure all fields are included

func (*DomainEntry) PathName

func (e *DomainEntry) PathName() string

func (*DomainEntry) SetMetadata added in v0.0.14

func (e *DomainEntry) SetMetadata(m *pb.Metadata)

type DomainResponse

type DomainResponse struct {
	// Success indicates whether the operation was successful.
	// @Description Whether the operation was successful
	Success bool `json:"success" example:"true"`

	// Data contains the domain entry if the operation was successful.
	// @Description Domain entry data if the operation was successful
	Data *DomainEntry `json:"data,omitempty"`

	// Error contains an error message if the operation failed.
	// @Description Error message if the operation failed
	Error string `json:"error,omitempty" example:"Domain not found"`
}

DomainResponse represents a response containing a single domain entry. It includes a success flag, the domain data, and an optional error message. @Description Response containing a single domain entry

type DomainsResponse

type DomainsResponse struct {
	// Success indicates whether the operation was successful.
	// @Description Whether the operation was successful
	Success bool `json:"success" example:"true"`

	// Data contains the list of domain entries if the operation was successful.
	// @Description List of domain entries if the operation was successful
	Data DomainEntries `json:"data,omitempty"`

	// Error contains an error message if the operation failed.
	// @Description Error message if the operation failed
	Error string `json:"error,omitempty" example:"Failed to load domains"`
}

DomainsResponse represents a response containing multiple domain entries. It includes a success flag, a list of domain data, and an optional error message. @Description Response containing multiple domain entries

type PaginatedDomainsResponse added in v0.6.0

type PaginatedDomainsResponse struct {
	// Success indicates whether the operation was successful
	// @Description Whether the operation was successful
	Success bool `json:"success" example:"true"`

	// Data contains the list of domain entries if the operation was successful
	// @Description List of domain entries if the operation was successful
	Data DomainEntries `json:"data,omitempty"`

	// Pagination contains pagination metadata
	// @Description Pagination metadata
	Pagination *PaginationInfo `json:"pagination,omitempty"`

	// Error contains an error message if the operation failed
	// @Description Error message if the operation failed
	Error string `json:"error,omitempty" example:"Failed to load domains"`
}

PaginatedDomainsResponse represents a paginated response containing multiple domain entries @Description Paginated response containing multiple domain entries

type PaginationInfo added in v0.6.0

type PaginationInfo struct {
	// CurrentPage is the current page number (1-based)
	// @Description Current page number (1-based)
	CurrentPage int `json:"current_page" example:"2"`

	// PerPage is the number of items per page
	// @Description Number of items per page
	PerPage int `json:"per_page" example:"100"`

	// Total is the total number of items
	// @Description Total number of items
	Total int `json:"total" example:"150"`

	// TotalPages is the total number of pages
	// @Description Total number of pages
	TotalPages int `json:"total_pages" example:"2"`

	// HasNext indicates if there is a next page
	// @Description Whether there is a next page
	HasNext bool `json:"has_next" example:"true"`

	// HasPrev indicates if there is a previous page
	// @Description Whether there is a previous page
	HasPrev bool `json:"has_prev" example:"true"`

	// NextURL is the URL for the next page
	// @Description URL for the next page
	NextURL string `json:"next_url,omitempty" example:"/api/v1/domains?page=3&per_page=100"`

	// PrevURL is the URL for the previous page
	// @Description URL for the previous page
	PrevURL string `json:"prev_url,omitempty" example:"/api/v1/domains?page=1&per_page=100"`
}

PaginationInfo contains pagination metadata for responses @Description Pagination metadata for responses

type UpdateDomainRequest

type UpdateDomainRequest struct {
	// AlternativeNames is a list of additional domain names.
	// @Description List of additional domain names (e.g., "www.example.com")
	AlternativeNames *[]string `json:"alternative_names,omitempty" example:"www.example.com,api.example.com"`

	// Alias is an optional alternative identifier.
	// @Description Optional alternative identifier for the domain
	Alias *string `json:"alias,omitempty" example:"my-domain"`

	// Enabled indicates whether the domain should be active.
	// @Description Whether the domain is enabled for certificate issuance
	Enabled *bool `json:"enabled,omitempty" example:"true"`

	// Comment is an optional description.
	// @Description Optional description or comment for the domain
	Comment *string `json:"comment,omitempty" example:"Production domain for web application"`
}

UpdateDomainRequest represents a request to update an existing domain entry. It contains the fields that can be modified for an existing domain. @Description Request to update an existing domain entry

Jump to

Keyboard shortcuts

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