An experimental pub/sub client and server project.

Error handling

Changed files
+8
server
+4
server/message_store.go
··· 5 5 "sync" 6 6 ) 7 7 8 + // Memory store allows messages to be stored in memory 8 9 type MemoryStore struct { 9 10 mu sync.Mutex 10 11 msgs map[int]message 11 12 offset int 12 13 } 13 14 15 + // New memory store initializes a new in memory store 14 16 func NewMemoryStore() *MemoryStore { 15 17 return &MemoryStore{ 16 18 msgs: make(map[int]message), 17 19 } 18 20 } 19 21 22 + // Write will write the provided message to the in memory store 20 23 func (m *MemoryStore) Write(msg message) error { 21 24 m.mu.Lock() 22 25 defer m.mu.Unlock() ··· 28 31 return nil 29 32 } 30 33 34 + // ReadFrom will read messages from (and including) the provided offset and pass them to the provided handler 31 35 func (m *MemoryStore) ReadFrom(offset int, handleFunc func(msg message)) error { 32 36 if offset < 0 || offset > m.offset { 33 37 return fmt.Errorf("invalid offset provided")
+4
server/subscriber.go
··· 44 44 offset := startAt 45 45 46 46 go func() { 47 + if startAt < 0 { 48 + return 49 + } 50 + 47 51 err := topic.messageStore.ReadFrom(offset, func(msg message) { 48 52 s.messages <- msg 49 53 })