Skip to content

Commit

Permalink
♻️ refactor: updated codebase #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Sep 23, 2023
1 parent 2f51eb7 commit 3832816
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 45 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/pnguyen215/gobase-voip-core
go 1.20

require (
github.com/go-resty/resty/v2 v2.7.0
github.com/json-iterator/go v1.1.12
github.com/nyaruka/phonenumbers v1.1.6
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
Expand All @@ -13,6 +12,5 @@ require (
github.com/golang/protobuf v1.3.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
golang.org/x/text v0.3.7 // indirect
)
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand All @@ -21,13 +19,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo=
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
2 changes: 0 additions & 2 deletions pkg/ami/ami_dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,9 @@ func (d *AMIDictionary) AddKeysTranslator(script map[string]string) *AMIDictiona
// https://raw.githubusercontent.com/pnguyen215/gear-insights-free/master/ami.dictionaries.json
func (d *AMIDictionary) AddKeyLinkTranslator(link string) *AMIDictionary {
keys, err := ForkDictionaryFromLink(link, false)

if err != nil {
return d
}

d.AddKeysTranslator(*keys)
return d
}
41 changes: 9 additions & 32 deletions pkg/ami/ami_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"
"time"

"github.com/go-resty/resty/v2"
"github.com/nyaruka/phonenumbers"
"github.com/pnguyen215/gobase-voip-core/pkg/ami/config"

Expand Down Expand Up @@ -474,38 +473,16 @@ func IsStringEmpty(str string) bool {
// Link must be provided to file formatted as json
// Return maps[string]string
func ForkDictionaryFromLink(link string, debug bool) (*map[string]string, error) {
client := resty.New()
c := NewRestify(link)
c.SetDebug(debug)
c.SetMaxRetries(3)
c.AddHeader("Content-Type", "application/json")
c.SetRetryCondition(func(response *http.Response, err error) bool {
return response.StatusCode >= 400 || response.StatusCode >= 500
})
result := &map[string]string{}
// Set retry count to non zero to enable retries
client.SetRetryCount(3).
// You can override initial retry wait time.
// Default is 100 milliseconds.
SetRetryWaitTime(10 * time.Second).
// MaxWaitTime can be overridden as well.
// Default is 2 seconds.
SetRetryMaxWaitTime(20 * time.Second).
AddRetryCondition(
// RetryConditionFunc type is for retry condition function
// input: non-nil Response OR request execution error
func(r *resty.Response, err error) bool {
return r.StatusCode() >= http.StatusBadRequest && r.StatusCode() <= http.StatusNetworkAuthenticationRequired
},
).
// Enable debug mode
SetDebug(debug).
// Add headers
SetHeaders(map[string]string{
"Content-Type": "application/json",
})

_, err := client.R().SetResult(&result).ForceContentType("application/json").Get(link)

if err != nil {
log.Printf("fork dictionary from link %v has error occurred %v", link, err.Error())
return result, err
}

return result, nil
err := c.Get("", make(map[string]string), &result)
return result, err
}

func VarsMap(values []string) map[string]string {
Expand Down

0 comments on commit 3832816

Please sign in to comment.