-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.go
53 lines (40 loc) · 919 Bytes
/
example.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
53
package main
import (
"log/slog"
"os"
"time"
"github.com/stym06/rebuf/rebuf"
)
func writeToStdout(data []byte) error {
slog.Info(string(data))
return nil
}
func main() {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
//Init the RebufOptions
rebufOptions := &rebuf.RebufOptions{
LogDir: "/Users/satyamraj/personal/rebuf/data",
FsyncTime: 5 * time.Second,
MaxLogSize: 50,
MaxSegments: 5,
Logger: logger,
}
//Init Rebuf
rebuf, err := rebuf.Init(rebufOptions)
if err != nil {
logger.Info("Error during Rebuf creation: " + err.Error())
}
defer rebuf.Close()
// Write Bytes
for i := 0; i < 30; i++ {
logger.Info("Writing data: ", "iter", i)
go rebuf.Write([]byte("Hello world"))
time.Sleep(300 * time.Millisecond)
}
//Replay and write to stdout
rebuf.Replay(writeToStdout)
if err != nil {
logger.Info(err.Error())
}
time.Sleep(30 * time.Second)
}