Skip to content

Commit

Permalink
fixing modify record function
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyup-Devop committed Jan 5, 2024
1 parent f5caabc commit c2f8827
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions records.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type RecordResponse struct {
Status *int `json:"status"`
}

type RecordsListParams struct {
type RecordListParams struct {
auth.Auth `json:",inline"`
DomainName *string `json:"domain-name" validate:"required"`
Host *string `json:"host,omitempty"`
Expand All @@ -52,7 +52,7 @@ type Record struct {
Status *int `json:"status"`
}

type RecordsListResponse struct {
type RecordListResponse struct {
Page *int `json:"page"`
RowsPerPage *int `json:"rows-per-page"`
PageCount *int `json:"page-count"`
Expand Down
12 changes: 6 additions & 6 deletions records/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ func (c Client) GetRecord(params *cloudns.RecordParams) (*cloudns.RecordResponse
return response, err
}

func GetRecordList(params *cloudns.RecordsListParams) (*cloudns.RecordsListResponse, error) {
func GetRecordList(params *cloudns.RecordListParams) (*cloudns.RecordListResponse, error) {
return getC().GetRecordList(params)
}

func (c Client) GetRecordList(params *cloudns.RecordsListParams) (*cloudns.RecordsListResponse, error) {
func (c Client) GetRecordList(params *cloudns.RecordListParams) (*cloudns.RecordListResponse, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
result := &cloudns.RecordsListResponse{
result := &cloudns.RecordListResponse{
Page: params.Page,
RowsPerPage: params.RowsPerPage,
}
Expand All @@ -72,9 +72,9 @@ func (c Client) GetRecordList(params *cloudns.RecordsListParams) (*cloudns.Recor
}
}

recordsList := map[string]*cloudns.Record{}
err := c.B.Call(http.MethodPost, "/dns/records.json", params, &recordsList, false)
result.Records = recordsList
recordList := map[string]*cloudns.Record{}
err := c.B.Call(http.MethodPost, "/dns/records.json", params, &recordList, false)
result.Records = recordList
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion records/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGetRecord(t *testing.T) {
func TestListRecords(t *testing.T) {
cloudns.AuthId = authId
cloudns.AuthPassword = authPassword
params := &cloudns.RecordsListParams{
params := &cloudns.RecordListParams{
DomainName: cloudns.String("hedgus.com"),
Page: cloudns.Int(1),
RowsPerPage: cloudns.Int(50),
Expand Down
9 changes: 8 additions & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,25 @@ func Ttl(fl validator.FieldLevel) bool {
}

func Priority(fl validator.FieldLevel) bool {
if fl.Parent().FieldByName("RecordType").Elem().String() == "MX" ||
if fl.Parent().FieldByName("RecordType").Elem().IsNil() ||
fl.Parent().FieldByName("RecordType").Elem().String() == "MX" ||
fl.Parent().FieldByName("RecordType").Elem().String() == "SRV" {
return true
}
return false
}

func Weight(fl validator.FieldLevel) bool {
if fl.Parent().FieldByName("RecordType").Elem().IsNil() {
return true
}
return fl.Parent().FieldByName("RecordType").Elem().String() == "SRV"
}

func Port(fl validator.FieldLevel) bool {
if fl.Parent().FieldByName("RecordType").Elem().IsNil() {
return true
}
return fl.Parent().FieldByName("RecordType").Elem().String() == "SRV"
}

Expand Down

0 comments on commit c2f8827

Please sign in to comment.