-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TTL and TXT #4
base: master
Are you sure you want to change the base?
Changes from all commits
bacdf5b
444277f
5d9c793
3a7d768
f64bedc
1b6446c
2007123
765f02d
a09acef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# OSX | ||
.DS_Store | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ package main | |
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/libdns/huaweicloud" | ||
"time" | ||
"github.com/jicjoy/huaweicloud" | ||
"github.com/libdns/libdns" | ||
) | ||
|
||
func main() { | ||
|
@@ -13,7 +14,14 @@ func main() { | |
SecretAccessKey: "YOUR_Secret_Key", | ||
} | ||
|
||
ret, err := p.GetRecords(context.TODO(), "your-domain") | ||
ret, err := p.SetRecords(context.TODO(), "iitmall.com",[]libdns.Record{ | ||
{ | ||
Type: "TXT", | ||
Name: "es", | ||
Value: "ssssfsdfsdf", | ||
TTL: time.Duration(10)* time.Second, | ||
}, | ||
}) | ||
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this. |
||
|
||
fmt.Println("Result:", ret) | ||
fmt.Println("Error:", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/libdns/huaweicloud | ||
module github.com/jicjoy/huaweicloud | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not change module name. |
||
|
||
go 1.23 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import ( | |
"context" | ||
"slices" | ||
"time" | ||
|
||
"github.com/devhaozi/huaweicloud-sdk-go-v3/services/dns/v2/model" | ||
"github.com/libdns/libdns" | ||
) | ||
|
@@ -65,16 +64,20 @@ func (p *Provider) AppendRecords(ctx context.Context, zone string, records []lib | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
|
||
|
||
for i, record := range records { | ||
//ttl | ||
parseTTL(&record) | ||
Comment on lines
+70
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix lint. |
||
|
||
ttl := int32(record.TTL.Seconds()) | ||
request := &model.CreateRecordSetRequest{ | ||
ZoneId: zoneId, | ||
Body: &model.CreateRecordSetRequestBody{ | ||
Name: libdns.AbsoluteName(record.Name, zone), | ||
Type: record.Type, | ||
Ttl: &ttl, | ||
Records: []string{record.Value}, | ||
Records: SolveRecordValue(record.Type,record.Value), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix lint. |
||
}, | ||
} | ||
response, err := client.CreateRecordSet(request) | ||
|
@@ -100,6 +103,11 @@ func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns | |
} | ||
|
||
for i, record := range records { | ||
|
||
//parse ttl | ||
//parseTTL(&record) | ||
record.TTL = time.Duration(300)* time.Second | ||
Comment on lines
+107
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix lint. |
||
|
||
// If the record id is empty try to get it by name and type | ||
if record.ID == "" { | ||
id, err := p.getRecordIdByNameAndType(ctx, zone, record.Name, record.Type) | ||
|
@@ -117,7 +125,7 @@ func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns | |
} else { | ||
name := libdns.AbsoluteName(record.Name, zone) | ||
ttl := int32(record.TTL.Seconds()) | ||
value := []string{record.Value} | ||
value := SolveRecordValue(record.Type,record.Value) | ||
request := &model.UpdateRecordSetRequest{ | ||
ZoneId: zoneId, | ||
RecordsetId: record.ID, | ||
|
@@ -169,4 +177,4 @@ var ( | |
_ libdns.RecordAppender = (*Provider)(nil) | ||
_ libdns.RecordSetter = (*Provider)(nil) | ||
_ libdns.RecordDeleter = (*Provider)(nil) | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package huaweicloud | ||
import ( | ||
"fmt" | ||
"github.com/libdns/libdns" | ||
"time" | ||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix lint. |
||
) | ||
|
||
func parseTTL(record *libdns.Record) { | ||
ttl := int32(record.TTL.Seconds()) | ||
if ttl == 0 { | ||
record.TTL = time.Duration(300)* time.Second | ||
} | ||
|
||
} | ||
|
||
func SolveRecordValue(rType string,value string) []string { | ||
switch rType { | ||
case "TXT": | ||
value = fmt.Sprintf("\"%s\"", value) | ||
|
||
} | ||
|
||
return []string{value} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls run
gofmt
to fix lint.