management

package
v0.0.0-...-464045c Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists = errors.New("already exists")
	ErrNotFound      = errors.New("not found")
	ErrValidation    = errors.New("validation error")
	ErrInternalError = errors.New("internal error")
)

Functions

func CustomErrorToHTTPStatusCode

func CustomErrorToHTTPStatusCode(err error) int

func GormToCustomError

func GormToCustomError(err error) error

func MapRecordToRecordAdded

func MapRecordToRecordAdded(record Record) events.RecordAdded

func MapRecordToRecordUpdated

func MapRecordToRecordUpdated(record Record) events.RecordUpdated

func MapToRecordDeleted

func MapToRecordDeleted(zoneID uuid.UUID, recordID uuid.UUID) events.RecordDeleted

func MapToZoneDeleted

func MapToZoneDeleted(zoneID uuid.UUID) events.ZoneDeleted

func MapZoneToZoneCreated

func MapZoneToZoneCreated(zone Zone) events.ZoneCreated

func MustString

func MustString(data any) string

func String

func String(data any) (string, error)

Types

type ManagementService

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

func NewManagementService

func NewManagementService(repo Repository, mq mq.MessageQueue) *ManagementService

func (*ManagementService) AddRecord

func (m *ManagementService) AddRecord(record Record) (Record, error)

func (*ManagementService) CreateZone

func (m *ManagementService) CreateZone(zone Zone) (Zone, error)

func (*ManagementService) DeleteRecord

func (m *ManagementService) DeleteRecord(zoneID uuid.UUID, recordID uuid.UUID) error

func (*ManagementService) DeleteZone

func (m *ManagementService) DeleteZone(zoneID uuid.UUID) error

func (*ManagementService) GetRecord

func (m *ManagementService) GetRecord(zoneID uuid.UUID, recordID uuid.UUID) (Record, error)

func (*ManagementService) GetRecords

func (m *ManagementService) GetRecords(zoneID uuid.UUID) ([]Record, error)

func (*ManagementService) GetZone

func (m *ManagementService) GetZone(zoneID uuid.UUID) (Zone, error)

func (*ManagementService) GetZones

func (m *ManagementService) GetZones() ([]Zone, error)

func (*ManagementService) UpdateRecord

func (m *ManagementService) UpdateRecord(zoneID uuid.UUID, recordID uuid.UUID, record Record) (Record, error)

type Record

type Record struct {
	ID     uuid.UUID    `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
	ZoneID uuid.UUID    `gorm:"type:uuid" json:"zone_id"`
	Name   string       `gorm:"type:varchar(255);unique;not null" json:"name"`
	Type   RecordType   `gorm:"type:varchar(7);not null" json:"type"` // not using enums due to further update that might support other record types
	TTL    uint32       `gorm:"type:integer;check:ttl >= 0;not null" json:"ttl"`
	Value  pgtype.JSONB `gorm:"type:jsonb;not null" json:"value"`
	Zone   Zone         `gorm:"foreignKey:ZoneID;constraint:OnDelete:CASCADE" json:"-"`
}

type RecordType

type RecordType string
const (
	A     RecordType = "A"
	AAAA  RecordType = "AAAA"
	MX    RecordType = "MX"
	NS    RecordType = "NS"
	TXT   RecordType = "TXT"
	CNAME RecordType = "CNAME"
	PTR   RecordType = "PTR"
)

type Repository

type Repository interface {
	SaveZone(zone Zone) (Zone, error)
	FindZones() ([]Zone, error)
	FindZoneByID(zoneID uuid.UUID) (Zone, error)
	DeleteZoneByID(zoneID uuid.UUID) error
	SaveZoneRecord(record Record) (Record, error)
	FindZoneRecords(zoneID uuid.UUID) ([]Record, error)
	FindZoneRecordByID(zoneID uuid.UUID, recordID uuid.UUID) (Record, error)
	UpdateZoneRecordByID(zoneID uuid.UUID, recordID uuid.UUID, record Record) (Record, error)
	DeleteZoneRecordByID(zoneID uuid.UUID, recordID uuid.UUID) error
}

type Zone

type Zone struct {
	ID   uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
	Zone string    `gorm:"unique;not null" json:"zone"`
}

Directories

Path Synopsis
adapters

Jump to

Keyboard shortcuts

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