Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Gasch committed Sep 4, 2023
1 parent 8938680 commit 935bbeb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ a SOAP-based events API into an HTTP/REST streaming API.

# Usage

The API is intentionally kept minimal. A new `Log` is constructed with
`memlog.New(ctx, options...)`. Data as `[]byte` is written to the log with
`Log.Write(ctx, data)`.
```go
ml, _ := memlog.New(ctx) // create log
offset, _ := ml.Write(ctx, []byte("Hello World")) // write some data
record, _ := ml.Read(ctx, offset) // read back data
fmt.Printf(string(record.Data)) // prints "Hello World"
```

The `memlog` API is intentionally kept minimal. A new `Log` is constructed with `memlog.New(ctx, options...)`. Data as
`[]byte` is written to the log with `Log.Write(ctx, data)`.

The first write to the `Log` using *default* `Options` starts at position
(`Offset`) `0`. Every write creates an immutable `Record` in the `Log`.
Expand Down Expand Up @@ -89,7 +95,7 @@ creating multiple `Logs` might be useful. For example:
💡 For use cases where you want to order the log by `key(s)`, consider using the
specialised [`sharded.Log`](sharded/README.md).

## Example
## Full Example

```go
package main
Expand Down

0 comments on commit 935bbeb

Please sign in to comment.