Files

37 lines
958 B
Go

package dto
import "github.com/vasyakrg/dns-autoresolver/internal/model"
// RecordDTO is the JSONB representation of one DNS record in a template.
type RecordDTO struct {
Type string `json:"type"`
Name string `json:"name"`
TTL int `json:"ttl"`
Values []string `json:"values"`
}
// TemplateDoc is stored in templates.doc (jsonb).
type TemplateDoc struct {
Records []RecordDTO `json:"records"`
}
func FromModel(recs []model.Record) TemplateDoc {
out := TemplateDoc{Records: make([]RecordDTO, 0, len(recs))}
for _, r := range recs {
out.Records = append(out.Records, RecordDTO{
Type: string(r.Type), Name: r.Name, TTL: r.TTL, Values: r.Values,
})
}
return out
}
func (d TemplateDoc) ToModel() []model.Record {
out := make([]model.Record, 0, len(d.Records))
for _, r := range d.Records {
out = append(out, model.Record{
Type: model.RecordType(r.Type), Name: r.Name, TTL: r.TTL, Values: r.Values,
})
}
return out
}