Skip to content

Commit

Permalink
fix time format to time.duration
Browse files Browse the repository at this point in the history
Signed-off-by: Pravin Pushkar <[email protected]>
  • Loading branch information
pravinpushkar committed Jul 21, 2023
1 parent ec05809 commit 91ac665
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 55 deletions.
16 changes: 8 additions & 8 deletions configuration/azure/appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ func parseMetadata(meta configuration.Metadata) (metadata, error) {
return m, fmt.Errorf("azure appconfig error: specify %s or %s field in metadata", host, connectionString)
}

if m.MaxRetryDelay != nil {
m.internalMaxRetryDelay = time.Duration(*m.MaxRetryDelay)
if m.MaxRetryDelay != 0 {
m.internalMaxRetryDelay = m.MaxRetryDelay
}
if m.RetryDelay != nil {
m.internalRetryDelay = time.Duration(*m.RetryDelay)
if m.RetryDelay != 0 {
m.internalRetryDelay = m.RetryDelay
}
if m.SubscribePollInterval != nil {
m.internalSubscribePollInterval = time.Duration(*m.SubscribePollInterval)
if m.SubscribePollInterval != 0 {
m.internalSubscribePollInterval = m.SubscribePollInterval
}
if m.RequestTimeout != nil {
m.internalRequestTimeout = time.Duration(*m.RequestTimeout)
if m.RequestTimeout != 0 {
m.internalRequestTimeout = m.RequestTimeout
}

return m, nil
Expand Down
48 changes: 24 additions & 24 deletions configuration/azure/appconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ func TestInit(t *testing.T) {
testProperties := make(map[string]string)
testProperties[host] = "testHost"
testProperties[maxRetries] = "3"
testProperties[retryDelay] = "4000000000"
testProperties[maxRetryDelay] = "120000000000"
testProperties[subscribePollInterval] = "30000000000"
testProperties[requestTimeout] = "30000000000"
testProperties[retryDelay] = "4s"
testProperties[maxRetryDelay] = "120s"

Check failure on line 196 in configuration/azure/appconfig/appconfig_test.go

View workflow job for this annotation

GitHub Actions / Build linux_amd64 binaries

string `120s` has 6 occurrences, make it a constant (goconst)
testProperties[subscribePollInterval] = "30s"

Check failure on line 197 in configuration/azure/appconfig/appconfig_test.go

View workflow job for this annotation

GitHub Actions / Build linux_amd64 binaries

string `30s` has 12 occurrences, make it a constant (goconst)
testProperties[requestTimeout] = "30s"

m := configuration.Metadata{Base: mdata.Base{
Properties: testProperties,
Expand All @@ -217,10 +217,10 @@ func TestInit(t *testing.T) {
testProperties := make(map[string]string)
testProperties[connectionString] = "Endpoint=https://foo.azconfig.io;Id=osOX-l9-s0:sig;Secret=00000000000000000000000000000000000000000000"
testProperties[maxRetries] = "3"
testProperties[retryDelay] = "4000000000"
testProperties[maxRetryDelay] = "120000000000"
testProperties[subscribePollInterval] = "30000000000"
testProperties[requestTimeout] = "30000000000"
testProperties[retryDelay] = "4s"
testProperties[maxRetryDelay] = "120s"
testProperties[subscribePollInterval] = "30s"
testProperties[requestTimeout] = "30s"

m := configuration.Metadata{Base: mdata.Base{
Properties: testProperties,
Expand All @@ -244,10 +244,10 @@ func Test_parseMetadata(t *testing.T) {
testProperties := make(map[string]string)
testProperties[host] = "testHost"
testProperties[maxRetries] = "3"
testProperties[retryDelay] = "4000000000"
testProperties[maxRetryDelay] = "120000000000"
testProperties[subscribePollInterval] = "30000000000"
testProperties[requestTimeout] = "30000000000"
testProperties[retryDelay] = "4s"
testProperties[maxRetryDelay] = "120s"
testProperties[subscribePollInterval] = "30s"
testProperties[requestTimeout] = "30s"

meta := configuration.Metadata{Base: mdata.Base{
Properties: testProperties,
Expand Down Expand Up @@ -276,10 +276,10 @@ func Test_parseMetadata(t *testing.T) {
testProperties := make(map[string]string)
testProperties[connectionString] = "testConnectionString"
testProperties[maxRetries] = "3"
testProperties[retryDelay] = "4000000000"
testProperties[maxRetryDelay] = "120000000000"
testProperties[subscribePollInterval] = "30000000000"
testProperties[requestTimeout] = "30000000000"
testProperties[retryDelay] = "4s"
testProperties[maxRetryDelay] = "120s"
testProperties[subscribePollInterval] = "30s"
testProperties[requestTimeout] = "30s"

meta := configuration.Metadata{Base: mdata.Base{
Properties: testProperties,
Expand Down Expand Up @@ -309,10 +309,10 @@ func Test_parseMetadata(t *testing.T) {
testProperties[host] = "testHost"
testProperties[connectionString] = "testConnectionString"
testProperties[maxRetries] = "3"
testProperties[retryDelay] = "4000000000"
testProperties[maxRetryDelay] = "120000000000"
testProperties[subscribePollInterval] = "30000000000"
testProperties[requestTimeout] = "30000000000"
testProperties[retryDelay] = "4s"
testProperties[maxRetryDelay] = "120s"
testProperties[subscribePollInterval] = "30s"
testProperties[requestTimeout] = "30s"

meta := configuration.Metadata{Base: mdata.Base{
Properties: testProperties,
Expand All @@ -327,10 +327,10 @@ func Test_parseMetadata(t *testing.T) {
testProperties[host] = ""
testProperties[connectionString] = ""
testProperties[maxRetries] = "3"
testProperties[retryDelay] = "4000000000"
testProperties[maxRetryDelay] = "120000000000"
testProperties[subscribePollInterval] = "30000000000"
testProperties[requestTimeout] = "30000000000"
testProperties[retryDelay] = "4s"
testProperties[maxRetryDelay] = "120s"
testProperties[subscribePollInterval] = "30s"
testProperties[requestTimeout] = "30s"

meta := configuration.Metadata{Base: mdata.Base{
Properties: testProperties,
Expand Down
14 changes: 7 additions & 7 deletions configuration/azure/appconfig/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ package appconfig
import "time"

type metadata struct {
Host string `mapstructure:"host"`
ConnectionString string `mapstructure:"connectionString"`
MaxRetries int `mapstructure:"maxRetries"`
MaxRetryDelay *int `mapstructure:"maxRetryDelay"`
RetryDelay *int `mapstructure:"retryDelay"`
SubscribePollInterval *int `mapstructure:"subscribePollInterval"`
RequestTimeout *int `mapstructure:"requestTimeout"`
Host string `mapstructure:"host"`
ConnectionString string `mapstructure:"connectionString"`
MaxRetries int `mapstructure:"maxRetries"`
MaxRetryDelay time.Duration `mapstructure:"maxRetryDelay"`
RetryDelay time.Duration `mapstructure:"retryDelay"`
SubscribePollInterval time.Duration `mapstructure:"subscribePollInterval"`
RequestTimeout time.Duration `mapstructure:"requestTimeout"`

internalRequestTimeout time.Duration `mapstructure:"-"`
internalMaxRetryDelay time.Duration `mapstructure:"-"`
Expand Down
32 changes: 16 additions & 16 deletions configuration/azure/appconfig/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ metadata:
default: '3'
example: '10'
- name: retryDelay
description: "Specifies the initial amount of delay to use before retrying an operation, in nanoseconds. The delay increases exponentially with each retry up to the maximum specified by MaxRetryDelay. Defaults to 4 seconds. -1 disables delay between retries."
type: number
default: '4000000000'
example: '5000000000'
description: "Specifies the initial amount of delay to use before retrying an operation. The delay increases exponentially with each retry up to the maximum specified by MaxRetryDelay. Defaults to 4 seconds."
type: duration
default: '4s'
example: '5s'
- name: maxRetryDelay
description: "Specifies the maximum delay allowed before retrying an operation, in nanoseconds. Typically the value is greater than or equal to the value specified in RetryDelay. Defaults to 120 seconds. -1 disables the limit."
type: number
default: '120000000000'
example: '180000000000'
description: "Specifies the maximum delay allowed before retrying an operation. Typically the value is greater than or equal to the value specified in RetryDelay. Defaults to 120 seconds."
type: duration
default: '120s'
example: '180s'
- name: subscribePollInterval
description: "Specifies the poll interval for polling the subscribed keys for any changes, in nanoseconds. Default polling interval is set to 24 hours."
type: number
default: '86400000000000'
example: '240000000000'
description: "Specifies the poll interval for polling the subscribed keys for any changes. Default polling interval is set to 24 hours."
type: duration
default: '24h'
example: '5m'
- name: requesttimeout
description: "Specifies the time allowed to pass until a request is failed, in nanoseconds. Default timeout is set to 15 seconds."
type: number
default: '15000000000'
example: '30000000000'
description: "Specifies the time allowed to pass until a request is failed. Default timeout is set to 15 seconds."
type: duration
default: '15s'
example: '30s'

0 comments on commit 91ac665

Please sign in to comment.