draincloud-core/internal/config/config.go

71 lines
876 B
Go
Raw Normal View History

2024-10-11 19:37:43 +00:00
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
2024-10-17 20:20:42 +00:00
type FloatValue struct {
EmptyValue
2024-10-19 23:17:27 +00:00
Val float32
2024-10-17 20:20:42 +00:00
}
2024-10-11 19:37:43 +00:00
2024-10-17 20:20:42 +00:00
func (v FloatValue) Float() float32 {
2024-10-19 23:17:27 +00:00
return v.Val
2024-10-17 20:20:42 +00:00
}
2024-10-11 19:37:43 +00:00
2024-10-17 20:20:42 +00:00
type StringValue struct {
EmptyValue
2024-10-19 23:17:27 +00:00
Val string
2024-10-11 19:37:43 +00:00
}
func (v StringValue) String() string {
2024-10-19 23:17:27 +00:00
return v.Val
2024-10-11 19:37:43 +00:00
}
2024-10-17 20:20:42 +00:00
type IntValue struct {
EmptyValue
2024-10-19 23:17:27 +00:00
Val int
2024-10-11 19:37:43 +00:00
}
2024-10-17 20:20:42 +00:00
func (v IntValue) Int() int {
2024-10-19 23:17:27 +00:00
return v.Val
2024-10-17 20:20:42 +00:00
}
func (v IntValue) Float() float32 {
2024-10-19 23:17:27 +00:00
return float32(v.Val)
2024-10-11 19:37:43 +00:00
}
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
}