-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(settings): internal default helpers
- Loading branch information
Showing
10 changed files
with
132 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package defaults | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
func String(existing, defaultValue string) string { | ||
if existing != "" { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func Int(existing, defaultValue int) int { | ||
if existing != 0 { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func Uint16(existing, defaultValue uint16) uint16 { | ||
if existing != 0 { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func Duration(existing time.Duration, defaultValue time.Duration) time.Duration { | ||
if existing != 0 { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func IP(existing, defaultValue net.IP) net.IP { | ||
if existing != nil { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func BoolPtr(existing *bool, defaultValue bool) *bool { | ||
if existing != nil { | ||
return existing | ||
} | ||
return &defaultValue | ||
} | ||
|
||
func StringPtr(existing *string, defaultValue string) *string { | ||
if existing != nil { | ||
return existing | ||
} | ||
return &defaultValue | ||
} | ||
|
||
func DurationPtr(existing *time.Duration, defaultValue time.Duration) *time.Duration { | ||
if existing != nil { | ||
return existing | ||
} | ||
return &defaultValue | ||
} | ||
|
||
func HTTPClient(existing, defaultValue *http.Client) *http.Client { | ||
if existing != nil { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func Resolver(existing, defaultValue *net.Resolver) *net.Resolver { | ||
if existing != nil { | ||
return existing | ||
} | ||
return defaultValue | ||
} | ||
|
||
func PrometheusRegisterer(existing, defaultValue prometheus.Registerer) prometheus.Registerer { | ||
if existing != nil { | ||
return existing | ||
} | ||
return defaultValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters