Skip to content

Commit

Permalink
Update variable types
Browse files Browse the repository at this point in the history
  • Loading branch information
ejstreet committed Feb 23, 2023
1 parent 67780ce commit 8dceb93
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 34 deletions.
20 changes: 10 additions & 10 deletions omglol/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ func (c *Client) FilterDNSRecord(address string, filterCriteria map[string]inter
match = false
break
}
if id != *record.ID {
if id != record.ID {
match = false
break
}
case "Type":
if *record.Type != value.(string) {
if record.Type != value.(string) {
match = false
break
}
case "Name":
if strings.Contains(*record.Name, ".") && *record.Name != value.(string) {
if strings.Contains(record.Name, ".") && record.Name != value.(string) {
match = false
break
} else if !strings.Contains(*record.Name, ".") && "@" != value.(string) {
} else if !strings.Contains(record.Name, ".") && "@" != value.(string) {
match = false
break
}
case "Data":
if *record.Data != value.(string) {
if record.Data != value.(string) {
match = false
break
}
Expand Down Expand Up @@ -116,17 +116,17 @@ func (c *Client) FilterDNSRecord(address string, filterCriteria map[string]inter
match = false
break
}
if ttl != *record.TTL {
if ttl != record.TTL {
match = false
break
}
case "CreatedAt":
if *record.CreatedAt != value.(string) {
if record.CreatedAt != value.(string) {
match = false
break
}
case "UpdatedAt":
if *record.UpdatedAt != value.(string) {
if record.UpdatedAt != value.(string) {
match = false
break
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func (d *DNSRecord) ToString() string {
if d.Priority != nil {
priority = strconv.Itoa(int(*d.Priority))
}
return fmt.Sprintf("ID: %d, Type: %s, Name: %s, Data: %s, Priority: %s, TTL: %d, CreatedAt: %s, UpdatedAt: %s", *d.ID, *d.Type, *d.Name, *d.Data, priority, *d.TTL, *d.CreatedAt, *d.UpdatedAt)
return fmt.Sprintf("ID: %d, Type: %s, Name: %s, Data: %s, Priority: %s, TTL: %d, CreatedAt: %s, UpdatedAt: %s", d.ID, d.Type, d.Name, d.Data, priority, d.TTL, d.CreatedAt, d.UpdatedAt)
}

// Add a new DNS record. See https://api.omg.lol/#token-post-dns-create-a-new-dns-record
Expand Down Expand Up @@ -231,7 +231,7 @@ func (c *Client) UpdateDNSRecord(domain string, entry DNSEntry, record_id int64)
Data: entry.Data,
Priority: entry.Priority,
TTL: entry.TTL,
ID: record_id,
ID: record_id, //this is the important line
}

jsonData, err := json.Marshal(record)
Expand Down
6 changes: 3 additions & 3 deletions omglol/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestCreateAndDeleteDNSRecord(t *testing.T) {

t.Logf(r.ToString())

err = c.DeleteDNSRecord(testOwnedDomain, *r.ID)
err = c.DeleteDNSRecord(testOwnedDomain, r.ID)
if err != nil {
t.Errorf(err.Error())
}
Expand All @@ -95,14 +95,14 @@ func TestCreateUpdateDeleteDNSRecord(t *testing.T) {

t.Logf(create.ToString())

replace, err := c.UpdateDNSRecord(testOwnedDomain, *record2, *create.ID)
replace, err := c.UpdateDNSRecord(testOwnedDomain, *record2, create.ID)
if err != nil {
t.Errorf(err.Error())
}

t.Logf(replace.ToString())

err = c.DeleteDNSRecord(testOwnedDomain, *replace.ID)
err = c.DeleteDNSRecord(testOwnedDomain, replace.ID)
if err != nil {
t.Errorf(err.Error())
}
Expand Down
32 changes: 16 additions & 16 deletions omglol/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,25 @@ type DNSEntry struct {

// Return type for DNS related methods
type DNSRecord struct {
ID *int64 `json:"id"`
Type *string `json:"type"`
Name *string `json:"name"`
Data *string `json:"data"`
Priority *int64 `json:"priority"`
TTL *int64 `json:"ttl"`
CreatedAt *string `json:"created_at"`
UpdatedAt *string `json:"updated_at"`
ID int64 `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Data string `json:"data"`
Priority *int64 `json:"priority"`
TTL int64 `json:"ttl"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

type dnsRecordContent struct {
ID *int64 `json:"id"`
Type *string `json:"type"`
Name *string `json:"name"`
Content *string `json:"content"`
ID int64 `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Content string `json:"content"`
Priority *int64 `json:"priority"`
TTL *int64 `json:"ttl"`
CreatedAt *string `json:"created_at"`
UpdatedAt *string `json:"updated_at"`
TTL int64 `json:"ttl"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

type dnsChangeResponse struct {
Expand All @@ -149,5 +149,5 @@ type PersistentURL struct {
Name string `json:"name"`
URL string `json:"url"`
Counter *int64 `json:"counter"`
Listed *bool `json:"listed"`
Listed bool `json:"listed"`
}
31 changes: 26 additions & 5 deletions omglol/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewPersistentURL(Name, URL string, listed bool, Counter ...*int64) *Persist
return &PersistentURL{
Name: Name,
URL: URL,
Listed: &listed,
Listed: listed,
Counter: counter,
}
}
Expand All @@ -30,16 +30,31 @@ func (p *PersistentURL) ToString() string {
if p.Counter != nil {
counter = strconv.Itoa(int(*p.Counter))
}
return fmt.Sprintf("Name: %s, URL: %s, Counter: %s", p.Name, p.URL, counter)
return fmt.Sprintf("Name: %s, URL: %s, Listed: %t, Counter: %s", p.Name, p.URL, p.Listed, counter)
}

// Create a new PersistentURL. See https://api.omg.lol/#token-post-purls-create-a-new-purl
func (c *Client) CreatePersistentURL(domain string, purl PersistentURL) error {
if !*purl.Listed {
purl.Listed = nil

type purlRequest struct {
Name string `json:"name"`
URL string `json:"url"`
Listed *bool `json:"listed"`
}

jsonData, err := json.Marshal(purl)
p := purlRequest{
Name: purl.Name,
URL: purl.URL,
}

if !purl.Listed {
p.Listed = nil
} else {
t := true
p.Listed = &t
}

jsonData, err := json.Marshal(p)

req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/address/%s/purl", c.HostURL, domain), bytes.NewBuffer([]byte(jsonData)))

Expand Down Expand Up @@ -166,6 +181,12 @@ func (c *Client) ListPersistentURLs(address string) (*[]PersistentURL, error) {
x.Counter = purl.Counter
}

if purl.Listed == nil {
x.Listed = false
} else {
x.Listed = true
}

p = append(p, x)
}

Expand Down

0 comments on commit 8dceb93

Please sign in to comment.