1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-12 22:07:47 +02:00

Simplified Logs RPC. Cleaned up code. Added comments.

This commit is contained in:
Milos Gajdos
2019-11-28 18:08:48 +00:00
parent 612f872f76
commit 7f1dea72f2
6 changed files with 51 additions and 18 deletions

View File

@ -6,12 +6,14 @@ import (
"time"
)
// Buffer is ring buffer
type Buffer struct {
size int
sync.RWMutex
vals []*Entry
}
// Entry is ring buffer data entry
type Entry struct {
Value interface{}
Timestamp time.Time
@ -43,14 +45,14 @@ func (b *Buffer) Put(v interface{}) {
// Get returns the last n entries
func (b *Buffer) Get(n int) []*Entry {
b.RLock()
defer b.RUnlock()
// reset any invalid values
if n > b.size || n < 0 {
n = b.size
}
b.RLock()
defer b.RUnlock()
// create a delta
delta := b.size - n