Skip to content

Commit

Permalink
fix: prevent porkbun rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidramiro committed Feb 26, 2023
1 parent aa3b85f commit 87be43d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/porkbun/porkbun.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"time"

"github.com/davidramiro/frigabun/internal/config"
"github.com/davidramiro/frigabun/internal/logger"
Expand Down Expand Up @@ -53,18 +54,25 @@ func (p *PorkbunDns) AddRecord() *PorkbunUpdateError {

queryErr := porkbunRequest.queryRecord(p)

time.Sleep(2 * time.Second)

if queryErr != nil && queryErr.Code == 409 {

logger.Log.Info().Msg("record exists, updating")
updateErr := porkbunRequest.updateRecord(p)

time.Sleep(2 * time.Second)

if updateErr != nil {
logger.Log.Error().Str("err", updateErr.Message).Msg("porkbun rejected updated record")
return &PorkbunUpdateError{Code: 400, Message: updateErr.Message}
}

} else {
createErr := porkbunRequest.createRecord(p)

time.Sleep(2 * time.Second)

if createErr != nil {
logger.Log.Error().Str("err", createErr.Message).Msg("porkbun rejected new record")
return &PorkbunUpdateError{Code: 400, Message: createErr.Message}
Expand Down

0 comments on commit 87be43d

Please sign in to comment.