Skip to content

Commit

Permalink
Leave distinction between null and empty
Browse files Browse the repository at this point in the history
  • Loading branch information
fformica committed Oct 8, 2024
1 parent 1bb7c89 commit ee0745b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions rest/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"

"gopkg.in/ns1/ns1-go.v2/rest/model/data"
"gopkg.in/ns1/ns1-go.v2/rest/model/dns"
)

Expand All @@ -26,9 +25,9 @@ func (s *RecordsService) Get(zone, domain, t string) (*dns.Record, *http.Respons
var r dns.Record
resp, err := s.client.Do(req, &r)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
if err.(*Error).Message == "record not found" {
if err.Message == "record not found" {
return nil, resp, ErrRecordMissing
}
}
Expand All @@ -45,11 +44,6 @@ func (s *RecordsService) Get(zone, domain, t string) (*dns.Record, *http.Respons
func (s *RecordsService) Create(r *dns.Record) (*http.Response, error) {
path := fmt.Sprintf("zones/%s/%s/%s", r.Zone, r.Domain, r.Type)

// the current API can't deal with nulls and this is not omitempty
if r.Regions == nil {
r.Regions = data.Regions{}
}

req, err := s.client.NewRequest("PUT", path, &r)
if err != nil {
return nil, err
Expand All @@ -58,9 +52,9 @@ func (s *RecordsService) Create(r *dns.Record) (*http.Response, error) {
// Update record fields with data from api(ensure consistent)
resp, err := s.client.Do(req, &r)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
switch err.(*Error).Message {
switch err.Message {
case "zone not found":
return resp, ErrZoneMissing
case "record already exists":
Expand All @@ -80,11 +74,6 @@ func (s *RecordsService) Create(r *dns.Record) (*http.Response, error) {
func (s *RecordsService) Update(r *dns.Record) (*http.Response, error) {
path := fmt.Sprintf("zones/%s/%s/%s", r.Zone, r.Domain, r.Type)

// the current API can't deal with nulls and this is not omitempty
if r.Regions == nil {
r.Regions = data.Regions{}
}

req, err := s.client.NewRequest("POST", path, &r)
if err != nil {
return nil, err
Expand All @@ -93,9 +82,9 @@ func (s *RecordsService) Update(r *dns.Record) (*http.Response, error) {
// Update records fields with data from api(ensure consistent)
resp, err := s.client.Do(req, &r)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
switch err.(*Error).Message {
switch err.Message {
case "zone not found":
return resp, ErrZoneMissing
case "record not found":
Expand Down Expand Up @@ -123,9 +112,9 @@ func (s *RecordsService) Delete(zone string, domain string, t string) (*http.Res

resp, err := s.client.Do(req, nil)
if err != nil {
switch err.(type) {
switch err := err.(type) {
case *Error:
if err.(*Error).Message == "record not found" {
if err.Message == "record not found" {
return resp, ErrRecordMissing
}
}
Expand Down

0 comments on commit ee0745b

Please sign in to comment.