-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (29 loc) · 820 Bytes
/
main.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
package graft
import (
"time"
"gopkg.in/yaml.v3"
)
type (
// Serializer "typeclass" in which an instance must be passed to graft on instantiation
Serializer[T any] struct {
ToString func(T) string
FromString func(string) T
}
graftConfig struct {
clusterConfig map[machineID]string
electionTimeoutDuration time.Duration
}
)
func parseGraftConfig(yamlConfig []byte) graftConfig {
parsedYaml := make(map[interface{}]interface{})
if err := yaml.Unmarshal(yamlConfig, &parsedYaml); err != nil {
panic(err)
}
timeout := parsedYaml["election_timeout"].(string)
clusterConfig := parsedYaml["cluster_configuration"].(map[machineID]string)
duration, _ := time.ParseDuration(timeout)
return graftConfig{
clusterConfig: clusterConfig,
electionTimeoutDuration: duration,
}
}