-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (39 loc) · 867 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"encoding/json"
"fmt"
"os"
"time"
"github.com/LightningDev1/go-memoizer"
)
// ProgramConfig is the config for the program.
type ProgramConfig map[string]any
// GetConfig gets the config for the program.
func GetConfig() (config *ProgramConfig, err error) {
content, err := os.ReadFile("./config.json")
if err != nil {
return nil, err
}
err = json.Unmarshal(content, &config)
if err != nil {
return nil, err
}
fmt.Println("Loaded config!")
return config, nil
}
// ConfigMemoizer is the memoizer for the config.
var ConfigMemoizer = memoizer.New(GetConfig, time.Second*5)
func doSomething(i int) {
config, err := ConfigMemoizer.Get()
if err != nil {
panic(err)
}
// Do something with the config.
fmt.Println(i, config)
}
func main() {
for i := 0; i < 50; i++ {
doSomething(i)
time.Sleep(time.Second)
}
}