-
Notifications
You must be signed in to change notification settings - Fork 29
/
config.go
47 lines (39 loc) · 1.09 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package flashdb
import (
"strconv"
"time"
)
const (
DefaultAddr = "127.0.0.1:8000"
DefaultMaxKeySize = uint32(1 * 1024)
DefaultMaxValueSize = uint32(8 * 1024)
)
type Config struct {
Addr string `json:"addr" toml:"addr"`
Path string `json:"path" toml:"path"` // dir path for append-only logs
EvictionInterval int `json:"eviction_interval" toml:"eviction_interval"` // in seconds
// NoSync disables fsync after writes. This is less durable and puts the
// log at risk of data loss when there's a server crash.
NoSync bool
}
func (c *Config) validate() {
if c.Addr == "" {
c.Addr = DefaultAddr
}
}
func (c *Config) evictionInterval() time.Duration {
return time.Duration(c.EvictionInterval) * time.Second
}
func DefaultConfig() *Config {
return &Config{
Addr: DefaultAddr,
Path: "/tmp/flashdb",
EvictionInterval: 10,
}
}
func float64ToStr(val float64) string {
return strconv.FormatFloat(val, 'f', -1, 64)
}
func strToFloat64(val string) (float64, error) {
return strconv.ParseFloat(val, 64)
}