mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-22 21:43:47 +00:00
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
|
|
"github.com/miekg/dns"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// ZoneRequest represents a Zone file request.
|
|
type ZoneRequest struct {
|
|
*Zone
|
|
|
|
User *User `json:"user,omitempty"`
|
|
RequestID string `json:"id"`
|
|
}
|
|
|
|
// ZoneResponse represents a Zone file request response.
|
|
type ZoneResponse struct {
|
|
*Zone
|
|
|
|
User *User `json:"user,omitempty"`
|
|
Elapsed int64 `json:"elapsed"`
|
|
}
|
|
|
|
// Zone struct represents a zonefile.
|
|
type Zone struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"` //nolint: tagliatelle
|
|
Body string `json:"body"`
|
|
}
|
|
|
|
// User struct represents a user.
|
|
type User struct {
|
|
gorm.Model
|
|
Username string
|
|
Password string
|
|
HashedPassword string
|
|
}
|
|
|
|
// Response struct represents a json response.
|
|
type Response struct {
|
|
Username string `json:"username,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
HTTPResponse int `json:"status,omitempty"`
|
|
}
|
|
|
|
// Parse will be used to parse zonefiles.
|
|
func (zone *ZoneRequest) Parse() error {
|
|
zp := dns.NewZoneParser(strings.NewReader(zone.Body), "", "")
|
|
|
|
for rr, ok := zp.Next(); ok; rr, ok = zp.Next() {
|
|
log.Println(rr)
|
|
}
|
|
|
|
if err := zp.Err(); err != nil {
|
|
return fmt.Errorf("unable to parse Zonefile: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|