71 lines
876 B
Go
71 lines
876 B
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type Provider interface {
|
|
GetValue(ctx context.Context, key Key) Value
|
|
}
|
|
|
|
type Key string
|
|
|
|
type Value interface {
|
|
Int() int
|
|
String() string
|
|
Float() float32
|
|
Duration() time.Duration
|
|
}
|
|
|
|
type DurationValue time.Duration
|
|
|
|
type FloatValue struct {
|
|
EmptyValue
|
|
val float32
|
|
}
|
|
|
|
func (v FloatValue) Float() float32 {
|
|
return v.val
|
|
}
|
|
|
|
type StringValue struct {
|
|
EmptyValue
|
|
val string
|
|
}
|
|
|
|
func (v StringValue) String() string {
|
|
return v.val
|
|
}
|
|
|
|
type IntValue struct {
|
|
EmptyValue
|
|
val int
|
|
}
|
|
|
|
func (v IntValue) Int() int {
|
|
return v.val
|
|
}
|
|
|
|
func (v IntValue) Float() float32 {
|
|
return float32(v.val)
|
|
}
|
|
|
|
type EmptyValue struct{}
|
|
|
|
func (v EmptyValue) Int() int {
|
|
return 0
|
|
}
|
|
|
|
func (v EmptyValue) String() string {
|
|
return ""
|
|
}
|
|
|
|
func (v EmptyValue) Float() float32 {
|
|
return 0
|
|
}
|
|
|
|
func (v EmptyValue) Duration() time.Duration {
|
|
return 0
|
|
}
|