Skip to content
/ clog Public

An educational implementation of a segmented log. Not suited for production.

License

RaphSku/clog

Repository files navigation

clog

An educational implementation of a segmented log. Not suited for production.

How to get clog?

Run

go get github.com/RaphSku/clog

to fetch clog as a dependency.

How to use clog?

Here is an example demonstrating how to use clog:

func convertStringToBytes(s string) []byte {
	buf := new(bytes.Buffer)
	buf.WriteString(s)

	return buf.Bytes()
}

func main() {
	logDir := "./logs"
	l, err := clog.NewLog(logDir)
	if err != nil {
		fmt.Printf("failed to create a new log: %v\n", err)
		os.Exit(1)
	}

	data := convertStringToBytes("Hello World!")
	err = l.Write(data)
	if err != nil {
		fmt.Printf("failed to write to log: %v\n", err)
		os.Exit(1)
	}

	offset := int64(0)
	data, err = l.Read(offset)
	if err != nil {
		fmt.Printf("failed to read from log: %v\n", err)
		os.Exit(1)
	}
	fmt.Printf("Fetched the following message at offset %d: %s\n", offset, string(data))
}

About

An educational implementation of a segmented log. Not suited for production.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages