envvars/vars.go

84 lines
2.1 KiB
Go
Raw Permalink Normal View History

2022-01-20 12:23:20 +01:00
package envvars
2022-08-25 10:18:22 +02:00
import "time"
2022-01-20 12:23:20 +01:00
func String(key, defaultValue string) string {
2022-08-25 10:18:22 +02:00
return Object(key, defaultValue, ConvertString)
2022-01-20 12:23:20 +01:00
}
func Byte(key string, defaultValue byte) byte {
return Uint8(key, defaultValue)
}
func Rune(key string, defaultValue rune) rune {
2022-08-25 10:18:22 +02:00
return Object(key, defaultValue, ConvertRune)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Int64(key string, defaultValue int64) int64 {
return Object(key, defaultValue, ConvertInt64)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Int32(key string, defaultValue int32) int32 {
return Object(key, defaultValue, ConvertInt32)
2022-01-20 12:23:20 +01:00
}
func Int16(key string, defaultValue int16) int16 {
2022-08-25 10:18:22 +02:00
return Object(key, defaultValue, ConvertInt16)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Int8(key string, defaultValue int8) int8 {
return Object(key, defaultValue, ConvertInt8)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Int(key string, defaultValue int) int {
return Object(key, defaultValue, ConvertInt)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Uint64(key string, defaultValue uint64) uint64 {
return Object(key, defaultValue, ConvertUint64)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Uint32(key string, defaultValue uint32) uint32 {
return Object(key, defaultValue, ConvertUint32)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Uint16(key string, defaultValue uint16) uint16 {
return Object(key, defaultValue, ConvertUint16)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Uint8(key string, defaultValue uint8) uint8 {
return Object(key, defaultValue, ConvertUint8)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Uint(key string, defaultValue uint) uint {
return Object(key, defaultValue, ConvertUint)
2022-01-20 12:23:20 +01:00
}
func Float64(key string, defaultValue float64) float64 {
2022-08-25 10:18:22 +02:00
return Object(key, defaultValue, ConvertFloat64)
2022-01-20 12:23:20 +01:00
}
2022-08-25 10:18:22 +02:00
func Float32(key string, defaultValue float32) float32 {
return Object(key, defaultValue, ConvertFloat32)
2022-01-20 12:23:20 +01:00
}
func Complex128(key string, defaultValue complex128) complex128 {
2022-08-25 10:18:22 +02:00
return Object(key, defaultValue, ConvertComplex128)
}
func Complex64(key string, defaultValue complex64) complex64 {
return Object(key, defaultValue, ConvertComplex64)
2022-01-20 12:23:20 +01:00
}
func Bool(key string, defaultValue bool) bool {
2022-08-25 10:18:22 +02:00
return Object(key, defaultValue, ConvertBool)
}
func Time(key string, defaultValue time.Time, layout string) time.Time {
return Object(key, defaultValue, func(s string) (time.Time, error) { return time.Parse(layout, s) })
}
func Duration(key string, defaultValue time.Duration) time.Duration {
return Object(key, defaultValue, time.ParseDuration)
2022-08-03 20:08:23 +02:00
}